Setting Global Variables from UserForm

vikasnitk85

New Member
Joined
Dec 13, 2012
Messages
2
Hi Guys,

How to call global variable from UserForm in the module.


I have written following codes for userform.


Public AnalysisVar As String

Private Sub UserForm_Initialize()
ChartAnalysisButton.Value = True
End Sub


Private Sub AnalysisOK_Click()
If ChartAnalysisButton.Value = True Then
AnalysisVar = "Chart"
Else
AnalysisVar = "Table"
End If

AnalysisTypeForm.Hide 'To close the form after clicking OK.
End Sub

Private Sub AnalysisCancel_Click()
Unload Me
End Sub




Then I am calling this userform from the module.
Sub PrintVar()
AnalysisTypeForm.Show
MsgBox (AnalysisVar)
End Sub




But When it completes the excution of AnalysisTypeForm.Show the value of AnalysisVar become null. And I get an empty message box. Guys please help me. where i am doing wrong.
confused.gif


Thanks & Regards,
Vikas Agrawal
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,216,558
Messages
6,131,400
Members
449,648
Latest member
kyouryo

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