#1   Report Post  
Jeff
 
Posts: n/a
Default Passing Variables

Sorry to keep asking questions about passing variables, but here is another
one hope you can help.

I have a macro that received one set of values so I call it
Macro1(X), where X is the value that is received. But Macro1(X) calculates
about 20 other variables Y,Z,A,.... using the value X. If I call Macro1(X)
and I need one of the variables how do I get it, do I have to declare global
variables.

Thanks
  #2   Report Post  
Chip Pearson
 
Posts: n/a
Default Passing Variables

First of all, ensure that you have Option Explicit as the very
first line in the code module (before and outside of any
procedure). This will force you to declare all your variable
rather than have VBA automatically allocate variable at run time.
Then read up on "scope" in the VBA Help file.

If you declare (Dim) the variable within Macro1, that variable is
accessible only within Macro1. When Macro1 exits, the variable is
destroyed. If you need to use calculated variables in more than
one procedure, declare them as Public outside of and before any
procedure.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jeff" wrote in message
...
Sorry to keep asking questions about passing variables, but
here is another
one hope you can help.

I have a macro that received one set of values so I call it
Macro1(X), where X is the value that is received. But
Macro1(X) calculates
about 20 other variables Y,Z,A,.... using the value X. If I
call Macro1(X)
and I need one of the variables how do I get it, do I have to
declare global
variables.

Thanks



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
VBA passing variables through a function Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:23 PM
Passing variables between a form and macro David New Users to Excel 1 October 5th 05 04:42 AM
Passing variables between a form and macro David New Users to Excel 4 September 23rd 05 11:57 AM
augmenter le nombre de cellules variables du solveur excel Alfomeg Excel Discussion (Misc queries) 0 August 4th 05 09:40 AM
How do I use variables in Excel? XUT67 New Users to Excel 2 July 21st 05 05:09 PM


All times are GMT +1. The time now is 08:12 AM.

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

About Us

"It's about Microsoft Excel"