Using values from one macro in another!

A

aiyer

Hi all!

I've assigned a value to a variable (X) declared in a certain macro.
was wondering if there would be a way for me to use the VERY SAM
variable X (which has the stored value in it) in another macro?

I would appreciate any help.

Thanks,

Arun.....
VTec corp
 
B

Bob Phillips

Declare it as a Public variable in a standard module, outside of any macro,
at the top of the code.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
R

Rob van Gelder

You can turn the variable into a global variable so that both procedures can
access it:
eg.

Dim myvar As Long

Sub test1()
myvar = 123
End Sub

Sub test2()
MsgBox myvar
End Sub
 
O

onedaywhen

Pass it to the second macro as an argument. If the second variable
need to use the variable itself (i.e. potentially change its value)
pass it by reference, otherwise pass it by value:

Sub Macro1()
Dim X As Long
X = 2
Macro2 X
Macro3 X
End Sub

Sub Macro2(ByVal Value As Long)
MsgBox CStr(Value)
End Sub

Sub Macro3(ByRef arg As Long)
arg = arg + 10
MsgBox CStr(arg)
End Sub
 
Top