ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variables (https://www.excelbanter.com/excel-programming/308509-variables.html)

MIKEYMAY

Variables
 
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?

mangesh_yadav[_59_]

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

Dim Var1

- Manges

--
Message posted from http://www.ExcelForum.com


No Name

Variables
 
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.

-----Original Message-----
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?
.


Harald Staff

Variables
 
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

"mikeymay" skrev i melding
...
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?




Rune Pedersen

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

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

"mikeymay" wrote in message
...
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?





All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com