ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing variable to and from a form (https://www.excelbanter.com/excel-programming/392563-passing-variable-form.html)

dan

Passing variable to and from a form
 
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

NickHK

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





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

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