ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable in one sub which refers to an input box in another sub. (https://www.excelbanter.com/excel-programming/392478-variable-one-sub-refers-input-box-another-sub.html)

Aaron

Variable in one sub which refers to an input box in another sub.
 
I have a sub that runs 17 other subs. It takes about a half hour to
complete. Throughout the 30 minutes various input boxes pop up. I want to
define all the variables through input boxes as the very first step so I can
walk away and I don't have to wait for each box to pop up as the program
runs. But that means having my variable is one sub and my variable
definition in another sub. This does not seem to work. How can I get a
defined variable to look into another sub for its meaning?

Tom Ogilvy

Variable in one sub which refers to an input box in another sub.
 
Public Var1
Public Var2

Sub Master()
var1 = Inputbox("enter value for var1")
var2 = InputBox("Enter value for var2")
ABC
EFG
End Sub

Sub ABC()
msgbox "Value of var1 is " & var1
End Sub

Sub EFG()
msgbox "Value of var2 is " & var2
End Sub

Another way is to pass the value of the variable to the sub in the argument
list.

--
Regards,
Tom Ogilvy


"Aaron" wrote:

I have a sub that runs 17 other subs. It takes about a half hour to
complete. Throughout the 30 minutes various input boxes pop up. I want to
define all the variables through input boxes as the very first step so I can
walk away and I don't have to wait for each box to pop up as the program
runs. But that means having my variable is one sub and my variable
definition in another sub. This does not seem to work. How can I get a
defined variable to look into another sub for its meaning?



All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com