Using Global Variables

skull_eagle

Board Regular
Joined
Mar 25, 2011
Messages
89
Hi, I'm setting up a sort of wizard where you make selections and move onto the next userform. There are 4 userforms in total and I want to set global variables to record the selections along the way.

I've set public variables outside of any sub or function
Public strFunction As String
Public strProcess As String

I've then set their values inside the sub
strFunction = ComboBox_Function.Value
strProcess = ListBox_Process.Value

When I try and use these variables at a later time to collate the results I get nothing
Public Sub UserForm_Initialize()
CF1.Caption = strFunction
CF2.Caption = strProcess
CF3.Caption = strSL
CF4.Caption = strSSL
End Sub

Any help would be most appreciated.

Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
...where you make selections and move onto the next userform. There are 4 userforms in total and I want to set global variables to record the selections along the way.

I've set public variables outside of any sub or function
Public strFunction As String
Public strProcess As String
...
....When I try and use these variables at a later time to collate the results I get nothing

Greetings,

When you say "outside", I presume you mean at the top of the Module. The question is: What kind of module, and (if you mean in the userform's module), has the userform that initially has the variables' declarations been removed from memory?

In general, you'd probably find it easiest to declare these variables in a Standard Module; or alternatively, you can pass the values (or objects, if any) from one userform to the next.

Mark
 
Upvote 0
Thanks GTO, I declared them in a standard module that contains nothing but a list of my variables. Works perfect.
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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