i am wrting a vba code where i will set some public var to use in many subs vars declared in userform code like this
public xxxx as string
sub vars()
xxxx = "test"
end sub
Private Sub CommandButton1_Click()
' test button
MsgBox ("pub var is " & xxxx)
End Sub
when i click in test buton the msg box is blank looks like it cant see the pub var aney ideas where is the problem (even if i set public xxxx as srtring in the code of a module or thisworkbook i get the same result) thanks
varssub and it saves"test"toxxxx, then the script stops running. Once the script stops, all your variables disappear - nothing is saved. You would need to callvarswithin theCommandButton1_Clicksub - if you really need to save a value between runs of the script, either save it in a cell (if using excel) or in a table (in Access).