Passing variable to and from a form
Dan,
It will not
- if you are not using "End" anywhere,
- or resetting your project, by using the <stop icon in the VBE.
- And in a standard module, you have
Dim YourVar As <SomeDataType
Also, are you using Option Explicit in all modules ?
<Standard Module code
Public MyVar As String
<Standard Module code
<UserForm code
Private Sub UserForm_Click()
MyVar = MyVar & "Updated from userform" & vbNewLine
End Sub
<UserForm code
<Worksheet code
Private Sub CommandButton1_Click()
MsgBox MyVar
UserForm1.Show 'Note showing modal
MsgBox MyVar
'End
End Sub
<Worksheet code
Test a few times, then uncomment the "End" and test a few more times.
NickHK
"Dan" wrote in message
...
If I declare a variable as Public in a normal module, then update the
variable in a form module - the update is lost as soon as I exit the form.
Any way around it?
Thanks
|