PDA

View Full Version : global variables



ProteanBeing
11-09-2007, 08:33 AM
how and where do I define global variables?

Bob Phillips
11-09-2007, 08:50 AM
Public myVar As String|Long|Boolean|Double|Object|Worksheet


at the start of a standard code module, in the declaratives section.

lucas
11-09-2007, 08:54 AM
For such a general question...from the help files:


Used at module level (http://javascript<b></b>:hhobj_4.Click()) to declare public variables (http://javascript<b></b>:hhobj_5.Click()) and allocate storage space.


Outside of any procedures....right below your Option explicit at the top of the standard module.

Example also from vba help:

Option Explicit
Public Number As Integer ' Public Integer variable.
Public NameArray(1 To 5) As String ' Public array variable.
' Multiple declarations, two Variants and one Integer, all Public.
Public MyVar, YourVar, ThisVar As Integer
Sub dosomething()
'do somthing using the public variables
end sub

ProteanBeing
11-09-2007, 08:55 AM
And myVar will be retained when used in subsequent modules?
An example would be that my data starts on row 8. If in the future I update it to start on row 9 I would like to only change one variable that represents this value for all of the associated modules of the workbook.

Bob Phillips
11-09-2007, 08:57 AM
Yes.

Bob Phillips
11-09-2007, 08:58 AM
But you should also be more dynamic, don't rely on hard-coding a start row within the code, but determine that row number by using some identifying criteria.

ProteanBeing
11-09-2007, 09:05 AM
normally I do. But I am making A LOT of small modules with a short amount of alotted time. I will probably go back and do that but for now I have to work fast. Thank for your help. :)

unmarkedhelicopter
11-09-2007, 09:13 AM
"There's going to be so many bugs in this software I have got to start work RIGHT NOW !"
Just a thought ...