#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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?
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
More than 1 Variables [email protected] Excel Discussion (Misc queries) 1 November 29th 06 02:09 AM
Variables in VBA Jeff Excel Discussion (Misc queries) 2 October 17th 06 02:30 PM
Variables Tim U[_2_] Excel Programming 2 June 22nd 04 10:12 PM
variables jim c. Excel Programming 1 October 16th 03 01:31 PM


All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"