Variables to be use by different Sub

  • Thread starter Thread starter Learn-more
  • Start date Start date
L

Learn-more

In one Userform I had 2 Command Button calling 2 different Sub.

The first Sub will get input from Text Box and then store in cell A3,
eg Range("A3") = txtVal1.Text

How can I use the last txtVal1 and use it in the second Sub which was called
from another Command Button and under a second Userform.

Basically, I could not work out where and how I can declare the variable so
it can be use commonly in differen Sub in different Userform etc.

Thanks for helping.
Learn-more
 
Declare a public variable in a standard code module, set that variable to
the textbox1 value in the first userform, then access it from anywhere else,
even if the first userform is closed.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Hi there,
I had tried different declarations but still not make it work. The two Subs
are in 2 UserForms and I had no modules. So all the variables in first
UserForm not pass to second UserForm. The Subs were called from Command
Butter in Sheet or UserForm.
Also there is Unload Me somewhere in the Subs, not sure if it matters.
I was also searching for examples with more than one UserForm, any idea
where to find it.
Thanks a lot.
Learn-more
 
the declaration would be (just to clarify because you didn't specify)

instead of
Dim ws as Worksheet

it would be
Public ws as Worksheet

if you are unloading the userform, the variables will leave with it.
try changing it to hide.me; it will still be loaded, and the variables
will still be there. just make sure you actually unload the userform
later on or it will just sit there, hidden.
hope this helps.
:)
susan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top