Accessing Userform Variable Values in Module

xlnc4all

New Member
Joined
May 12, 2014
Messages
2
Hi All, I have a userform which has two variable and I want to use those variable values in multiple Modules

'Userform Submit Code

Private Sub SubmitButton_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "Please Enter Period Value"


ElseIf Me.ComboBox2.Value = "" Then
MsgBox "Please Enter Fiscal Year"


ElseIf Me.ComboBox1.Value <> "" And Me.ComboBox2.Value <> "" Then
Period = Me.ComboBox1.Value
FY = Me.ComboBox2.Value
Unload Me
End If


End Sub

******************Below is my Module*****
Public Period As String
Public FY As String

Sub MyModule()

Period = 'Here i want userform Period value
FY = 'Here i want userform FY value

End Sub

Thanks in advance
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Probably declare them as public at the top of one of the modules so they are available to all procedures/modules
 
Upvote 0
You can refer directly to the userform an it's controls in the module, provided the userform is still loaded.

So you could have this in the module,

Code:
Period = UserForm1.ComboBox1.Value
FY =UserForm2.ComboBox2.Value
and in the userform.
Code:
Me.Hide

Call MyModule

Unload Me
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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