Variables

  • Thread starter Thread starter mikeymay
  • Start date Start date
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?
 
You need to define the variable as global. Write in the beginning of th
module you define it as

Dim Var1

- Manges
 
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.
 
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
 
i'm not sure what you mean...
but might be this..

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top