Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using values from one macro in another!
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 -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using values from one macro in another!
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) "aiyer " wrote in message ... Hi all! I've assigned a value to a variable (X) declared in a certain macro. I was wondering if there would be a way for me to use the VERY SAME variable X (which has the stored value in it) in another macro? I would appreciate any help. Thanks, Arun..... VTec corp. --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using values from one macro in another!
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 -- Rob van Gelder - http://www.vangelder.co.nz/excel "aiyer " wrote in message ... Hi all! I've assigned a value to a variable (X) declared in a certain macro. I was wondering if there would be a way for me to use the VERY SAME variable X (which has the stored value in it) in another macro? I would appreciate any help. Thanks, Arun..... VTec corp. --- Message posted from http://www.ExcelForum.com/ |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using values from one macro in another!
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 -- aiyer wrote in message ... Hi all! I've assigned a value to a variable (X) declared in a certain macro. I was wondering if there would be a way for me to use the VERY SAME variable X (which has the stored value in it) in another macro? I would appreciate any help. Thanks, Arun..... VTec corp. --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Paste Values Macro | New Users to Excel | |||
macro for duplicate values | Excel Worksheet Functions | |||
Macro needed to Paste Values and prevent Macro operation | Excel Discussion (Misc queries) | |||
Macro needed to Paste Values and prevent Macro operation | Excel Discussion (Misc queries) | |||
Macro that copies values | Excel Programming |