Make another macro use variable from another macro

michaelsmith559

Well-known Member
Joined
Oct 6, 2013
Messages
881
Office Version
  1. 2013
  2. 2007
I have a line of code like this:

Code:
For pos1num = 6 To x
    Call Step_One
Next pos1num

When Step_One is called, this line:
Code:
Range("M2").Value = Range("M" & pos1num).Value
is highlighted and the pos1num shows as empty.

How can I have the macro Step_One reference pos1num from the other macro? Thanks for any help.

Mike
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Or, set-up your Step_One procedure to accept/take parameters, and pass in the value when calling it.
See: https://msdn.microsoft.com/en-us/library/aa263527(v=vs.60).aspx

Typically, you see the use of Global Variables when a value is being set once, and stays pretty static for the rest of the code (maybe changing once or twice depending on some conditions). However, if you are looping through a bunch of value, you typically see it when the procedure has parameters that are fed into it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top