Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Variables to be use by different Sub

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Variables to be use by different Sub

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)

"Learn-more" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Variables to be use by different Sub

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


"Bob Phillips" wrote:

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)

"Learn-more" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Variables to be use by different Sub

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


On Jun 13, 5:34*am, Learn-more
wrote:
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



"Bob Phillips" wrote:
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)


"Learn-more" wrote in message
...
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- Hide quoted text -


- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum if 2 variables ksel Excel Discussion (Misc queries) 6 June 18th 09 09:45 AM
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Storing variables in a macro and using those variables to performcalculations. [email protected] Excel Programming 3 December 10th 07 04:13 PM
Variables Mike NG Excel Programming 7 June 4th 05 03:19 PM
Variables Kelford Excel Programming 2 June 2nd 05 01:14 PM


All times are GMT +1. The time now is 11:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"