Variables

M

mikeymay

I am wanting to use a boolean variable, say Var1 named
from a User Form within a macro and then call up that
variable in a subsequent Sub routine that forms part of
the macro but when the sub routine is running Var1 is now
empty.

What am I doing wrong?
 
M

mangesh_yadav

You need to define the variable as global. Write in the beginning of th
module you define it as

Dim Var1

- Manges
 
G

Guest

if i understand you, you are runing 2 subs. when one sub
finishes, it dumps all of the variables. you will have to
redeclair var1 in the second sub.
 
H

Harald Staff

Apart from globals, my preference is to pass variables to the macros that
need them, like this:

Sub tester()
Dim B As Boolean
B = True
Call NextOne(B)
B = Not B
Call ThirdOne(B, "Simon says:")
End Sub

Sub NextOne(B As Boolean)
MsgBox "Next one says " & B
End Sub

Sub ThirdOne(B As Boolean, S As String)
MsgBox S & vbNewLine & B
End Sub

HTH. Best wishes Harald
 
R

Rune Pedersen

i'm not sure what you mean...
but might be this..

have you checked the scope of your vairable... if its global or not?
 
Top