Declaring Variables
Aug 23, 2007
I tend to use alot of sub but am finding I need to declare variables each time
for example
Sub Macro1
Dim i as integer
i = 10
some other code...
end sub
Sub Macro2
Dim i as integer
i = 10
some other code...
end sub
View 9 Replies
ADVERTISEMENT
Jul 17, 2014
I'm having trouble creating a macro that will look at a single URL, and based on what text is in a cell, replace that name and put it into a specific location in the URL. Then the URL will open and the rest is a macro I've written already. This will then be done as many times as need as long as there is text in the column.
So I'm looking to declare the text in these cells as different variables, then have something call these variables into a specific location in a URL, then have that URL (which is a worksheet location) open up. This is because I have many URL worksheet locations on an external website, I'd like for my macro to look at the cells in column A, check "A2" and whatever that name is, and have it placed into the URL. I assume some type of loop would be useful, since I do not want them to open up all at once, but one by one based on the text or variable in the column. Then the URL will open.
Then I can run my macro code which will include copying and pasting, closing and saving. Then go the next cell, check "A3" then repeat the process. The URL for all the worksheets are all the same, except for one specifc name, which is what im looking to replace one by one.
View 4 Replies
View Related
Apr 19, 2007
how do you declare public variables? In one of my forms I declare the variables but for some reason can not access them in other forms.
Public Rm_new As Integer
Public Angle_new As Integer
Public Pl_new As Integer
Public Sub cal_graph_Click()
'Stating variables
Rm_new = text_rm.Text
Angle_new = text_angle.Text
Pl_new = text_length.Text
View 3 Replies
View Related
Dec 22, 2011
Using Excel 2007, I'm trying to figure out (and not succeeding!) on how to declare worksheet and range - in order to:
input a formula to cell xfd1, then copy down to xfd2:xfd100 - and here's what I've been playing about with
Code:
Sub filldownxfd()
Dim src As Range, out As Range, wks As Worksheet
Dim sRangeName As String
Workbooks.Item(1).Sheets.Item ("Sheet1")
Dim example As Range
Set example = Range("xfd2:xfd100")
[code]....
View 2 Replies
View Related
Jan 21, 2007
where the number of rows and columns depend on other variables?
For example: In sheet 1, I have mentioned A = 2 and B = 3.
In the macro, I declare A and B to be integers. Then I try to declare a 2D array as follows:
Dim AB(A, B) As Integer
During compiling, it gives me an error: "Compile Error: Constant Expression Required" with the above line highlighted. What am I doing wrong?
Also, when I declare an array AB(4, 7), 4 is the number of rows and 7 is the number of columns, right?
View 11 Replies
View Related
Oct 29, 2008
Can anyone tell me how to have a variable which can store leading zero's. I am using this variable and part of a string and want it to be able to store and calculate numbers such as 0005 at the moment if such a number is entered it sees it as 5. At the moment I have declared the variables as integers but clearly this is incorrect.
View 9 Replies
View Related
Nov 23, 2011
I am trying to make sense of quite an elaborate macro built by someone else. This has the following line of code
Code:
Public Sub readOperation(rowNumber As Integer)
Dim rowOff As Integer
rowOff = rowNumber - 1
'other arguments and conditions
End Sub
What I am buggered about is that I cannot see the the variable rowNumber being declared anywhere but it seems to have a value of 1. I should mention that Operation is a class and I am very new to classes.
View 8 Replies
View Related
May 2, 2008
Using excel 2003
What is the proper declaration for a decimal, I’ve been using currency because it has two decimal points i.e.
Dim x as Currency ...
View 9 Replies
View Related
Jul 18, 2008
i got this at the top of my module:
Option Explicit
Public intLRow As Integer
Public strNetDrive As String
Public strDocName As String
Const strNetDrive = "\DriveDocuments"
Then i have this as a macro to test it:
Sub test()
Range("A1").Formula = strNetDrive
End Sub
When i run the macro i get this error:
View 9 Replies
View Related
Oct 20, 2006
I have a worksheet that has 2 sheets. I want to declare a variable that can be accessed for reading and/or overwriting by both of those sheets. Where do I declare it and how do I access it from Sheet1 for example?
View 4 Replies
View Related
Jun 11, 2007
Is it possible to declare n variable names dynamically in a macro? For example: Cell A2 in Sheet1 contains the number of variables to be considered in the macro (n). I would like all the variables to take names in the macro from node1 to noden using the dim statement. I tried running a for loop:
View 14 Replies
View Related
Jan 13, 2010
I'm trying to create an array of arrays (a jagged array). According to Microsoft's VB developer center I can declare in the following ways: ...
View 6 Replies
View Related
Jun 14, 2012
Right now in cell AE1 the value = "SUM", but the word "SUM" floats in row 1
I'd like a macro that looks through row1, and gives me the column letter that the word "SUM" resides in
sCol_1 As String
sCol1 = (Where ever the word "SUM" is located in row 1)
not sure if this is the best way.
View 2 Replies
View Related
Jul 28, 2009
Prior to declaring a variable i used this code and it worked:
Sheets("442000ON-1+6").Range("C7").formula = "my formula"
range(C7).select
Selection.AutoFill Destination:=Range("C7:N7"), Type:=xlFillDefault
Than i declared a variable b/c i have a number of formulas i need to use but still needed it to fill the formula in a series after the formula ran. I started getting an error.
Fix was:
Dim formula1 As String
formula1 = "=SUMIF(Pivot!$A$6:$A$108,'442000ON-1+6'!$C$3,INDEX(Pivot!$B$6:$BP$106,0,MATCH('442000ON-1+6'!$B$1,Pivot!$B$5:$BP$5)))"
Sheets("442000ON-1+6").Range("C7").formula = formula1
Range("C7").Select
Set SourceRange = Worksheets("442000ON-1+6").Range("C7")
Set fillRange = Worksheets("442000ON-1+6").Range("C7:N7")
SourceRange.AutoFill Destination:=fillRange
View 9 Replies
View Related
Apr 22, 2014
i'm trying to develop an array that is populated when a userform is activated. The userform has a command button that when pressed, will cross check the information filled out in the userform with the entries in the array. If there are no matches then the array is ReDim and the new information is added to the array. Once all the entries have been made. The array is then transposed to a sheet titled "Database". My problem is that vba is not allowing me declare a public array.Below is the first part of the code. Which is when the userform is activated.
Private Sub UserForm_Activate()
With Sheets("Resources")
cbZIP.List = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Value
cbBED.List = .Range("B2", .Range("B" & Rows.Count).End(xlUp)).Value
cbBATH.List = .Range("C2", .Range("C" & Rows.Count).End(xlUp)).Value
cbSTABRV.List = .Range("G2", .Range("G" & Rows.Count).End(xlUp)).Value
End With
[code]....
View 1 Replies
View Related
Jun 18, 2006
I am trying to compare two workbooks and am running into the problem that since I declared my two workbooks, I am limited in the methods that I can use. Here is all of the code so far.
Option Explicit
Sub UpdateMasterFile()
Dim wbMaster As Workbooks
Dim wbEmailed As Workbooks
Dim wsPC As Worksheet
Dim Master As Long
Dim Emailed As Long
Dim intMaster As Integer
Dim intEmailed As Integer
Set wbMaster = Workbooks("Master Info.xls").Sheets("PlantsCom")
Set wbEmailed = Workbooks("EmailedData.xls").Sheets("NewInfo")
Master = Workbooks("Master Info.xls").Sheets("PlantsCom"). Range("a65536").End(xlUp).Row
Emailed = Workbooks("EmailedData.xls").Sheets("NewInfo").Range("a65536").End(xlUp).Row..............
View 2 Replies
View Related
Sep 25, 2006
Users select a row number which then opens up a Userform. Comboboxes and Textboxes on this Userform are then populated with coloumn values (dependant on the row initially selected). If the row number was the same each time I could accomplish this by the following.
Private Sub TextBox1_Enter()
TextBox1.Value = Range("a1")
End Sub
but as its a variable I'm trying the following (which I think should work)
Private Sub TextBox1_Enter()
TextBox1.Value = Range("a" & edi & "")
End Sub
I think I need to declare the variable 'edi' as Public. If so where should this be? I've tried 'Genereal Declaration'
View 4 Replies
View Related
Feb 5, 2009
Unzip Code - Works without Variables, Breaks with Variables.... This has been driving me bananas...
I have the
View 2 Replies
View Related
Jul 27, 2006
Can a Function give two or more output variables. e.g.
Sub a()
x = 5
result = Y(x)
End Sub
Function Y (x As Integer) As Integer
Dim B
B = ... * x
Y = ... * B
this will give back Y as a result. But if I want to get 2 or more output variables (let's say I need to get also B into sub) from one function, how should I do that?
I need this because function works with large matrix and I want to extract some values appeared in between.
View 2 Replies
View Related
Apr 27, 2006
I'm trying to loop through a range in excel from access, checking where the titles (in Excel row 1) match with the fields (in a recordset in Access that is passed to the function) - and where they do, I want to dimension a variable to hold the column number - I'm not sure it's possible, but I'd be interested to know either way. The line I'm asking about is at the bottom of the code - the rest of the code is just to give context...
Sub ImportGeneric(rsImported As ADODB.Recordset, rsConfirmed As ADODB.Recordset)
Dim fd As FileDialog
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Worksheet
Dim iFilePicked As Integer
Dim strFilePath As String
fd.Filters.clear
fd.Filters.Add "Excel files", "*.xls"
fd.ButtonName = "Select"
iFilePicked = fd.Show
If iFilePicked = -1 Then
strFilePath = fd.SelectedItems(1)
Else ..................
View 3 Replies
View Related
Jan 16, 2007
i have a "problem" to empty / reset my variables. I defined them as vHour1_KW2 where the "1" is from 1 to 21 and the "2" starts from 1 to 53. Now I want to erase all of this variables or to set the value of them to "0".
At moment I use following
vHour1_KW1 = 0
vHour1_KW2 = 0
...
vHour1_KW53 = 0
vHour2_KW1 = 0
vHour2_KW2 = 0
...
vHour2_KW53 = 0
until...............................
View 3 Replies
View Related
Apr 9, 2014
I'm having a hard time understanding how to accomplish what seems to be a simple result.
I need to display one of two words, based on whether or not a pair of values are above or below the criteria.
FIRST:
IF H6 is greater than 5000
AND
IF AB6 is greater than 25000
Display: Double
SECOND:
IF H6 is less than 5000
AND
IF AB6 is greater than 25000
Display: Single
There is no 3rd scenario, even though logically there should be.
View 13 Replies
View Related
Apr 1, 2008
I am trying to put variables in this URL which is related to yahoo finance :
.Name="hp?s=NVDA&a=00&b=31&c=2001&d=11&e=29&f=2006&g=m&y=0"
I defined at the beginning
Dim start_date As Date
Dim end_date As Date
Dim datestring As Variant
start_date = #1/31/2001#
end_date = #11/26/2006#
and put them in datestring
I passed the datestring to a new sub which has the URL:
.Name="hp?s=NVDA&a=00&b=31&c=2001&d=11&e=29&f=2006&g=m&y=0"
So, my question is, i tried to put the (1/31/2001) and (26/11/2007) which is in the above URL which is separated in variables and the URL remain the same
View 11 Replies
View Related
Jul 6, 2012
I am trying to use COUNTIF with two critera. If this isn't possible is there any other way possible of doing this in a range of cells.
What I am trying to do is show the amount of students in a year group who spend x amount of hours on the internet and have a target grade (for example) of Lvl 4
I have been trying use a formula along the lines of =COUNTIF (Q5yr7, "0- 1Hour", Q12yr7, "4")
View 9 Replies
View Related
Jun 26, 2014
vlookup with 3 different variables, for example cells k4 k5 and k6 can be changed to give different variables. Is it possible to have a vlookup function in cell k9 which returns the correct % when the 3 variables are chosen. example, blue boat 48 would return %value of 21%
View 2 Replies
View Related
Aug 1, 2014
I am trying to count the status and type of some work so:
Column A would contain the status of the work e.g. open, in progress, closed etc.
Column B would contain the department: ict, development, operations, etc.
I want to do a summary that shows: How many are in ICT are open, closed etc.
I can do a countif to get the total open, in progress etc or total number of ICT jobs but not ICT In progress.
View 1 Replies
View Related
Feb 19, 2008
I am trying to add an additional criteria to the following sumproduct formula. The formula below works fine to add up values that are within a date range. However, I want to add values within a specified date range as well as one additional variable. The additional variable is in column G.
SUMPRODUCT(--($A$3:$A$1015>=$A1026),--($A$3:$A$1015<=$B1026),D$3:D$1015)
View 10 Replies
View Related
Nov 30, 2008
Trying to work out the formulas for placing plus minus variables above and below a cell as per worksheet attached. right hand side of the page
View 2 Replies
View Related
Jan 20, 2009
I want to make an excel funktion than can distinguish between 3 variables. The three variables are the outcomes of my first function which are 0, 1 and 2 these IF functions can be seen below:
=IF(B11>52;"1";"0")
=IF(B12>5;"1";"0")
Then when I have these results I have tried the following function:
=IF(C11+C12=2;"6-12";"4-6")
By using this function I get an output for 2 (true) and 0 (false), but I would also like an output for 1 (which would be 6 in my work)
It looks like this:
Var 1 58 1
Var 2 4 0
Suggestion 4-6
So in the above case where the sum of var1 and var2 is 1 it is only counted as false for not being 2 and therefore = 4-6 instead of what I would like it to be = 6 (for 1)
View 13 Replies
View Related
Apr 14, 2009
I'm trying to count cells in one column that match a variable only if it also matches a variable in another column. For example, I want to count all of the cells in column A that match "Franklin" only if column D shows "True".
View 5 Replies
View Related