Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default 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
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
Paste Values Macro John Calder New Users to Excel 4 May 28th 07 10:19 PM
macro for duplicate values italiavb Excel Worksheet Functions 0 February 7th 07 12:23 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM
Macro that copies values Bob Umlas[_3_] Excel Programming 0 December 3rd 03 03:29 PM


All times are GMT +1. The time now is 08:12 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"