Using values from one macro in another!

  • Thread starter Thread starter aiyer
  • Start date Start date
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
 
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)
 
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
 
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
 

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