fast question regarding variables

interner

New Member
Joined
Jun 20, 2011
Messages
44
I have a sub, inside this sub i call another sub. How do I get the variables from the latter sub to carry over to the firsts sub. Example below.

Code:
sub subnum1()
x = 5
y = 8

call subnum2
q = x + y + z
msgbox q
end sub
sub subnum2()
z = 9
end sub
when I attempt to calculate "q" as seen above, the value of "z" from subnum2 is not carried back up. How can I fix this?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Maybe like this

Code:
Sub subnum1()
x = 5
y = 8

Call subnum2(z)
q = x + y + z
MsgBox q
End Sub
Sub subnum2(z)
z = 9
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,611
Members
452,931
Latest member
The Monk

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