RE: Public / Private subs

philhowell

Board Regular
Joined
Jun 11, 2002
Messages
175
Could someone give me a quick run down on how variables are passed between subs, cheers

Phil
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
To pass a variable between subs you simply send it along to the procedure (passing parameters) as arguments:

Call ARoutine(MyName, MyAge)

the sub/function you are calling must have the same number of arguments as is sent or you'll get an error.

So, the receiving sub/function

Public Sub ARoutine(ByVal MyName As String, ByVal MyAge As Integer)

would look like that.

You don't need to use the ByVal statement which means you are passing the variable by its value meaning that the value will be used in the procedure but won't be affected elsewhere. You could also use the ByRef statement which will change the value of the variable within the database.

Don't have much time to go into it in detail but that should be enough to start with...
 
Upvote 0

Forum statistics

Threads
1,221,508
Messages
6,160,222
Members
451,631
Latest member
coffiajoseph

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