ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userforms and public variables (https://www.excelbanter.com/excel-programming/424189-userforms-public-variables.html)

chuckm

Userforms and public variables
 
Using Excel 2003 sp3
I have a simple userform with 2 commandbuttons. Commandbutton1
executes some code, macro1, that reads some data from the worksheet
and displays it on the userform...no problem. Commandbutton2
executes some code macro2, that reads some user input on the form and
further processes the data. The problem is that macro2 cannot access
variables defined in macro1.

It seemed to me that I could solve this by setting up public
variables, but either I am wrong or am not setting it up correctly.
Can someone please help?
thanks
chuckm

joel

Userforms and public variables
 
On etrick is to make invisible text boxes on the userform and pass variables
by putting the variables into the text boxes. You could also use public
varibles. You may have to remove the Private property from the subroutine
functions.

"chuckm" wrote:

Using Excel 2003 sp3
I have a simple userform with 2 commandbuttons. Commandbutton1
executes some code, macro1, that reads some data from the worksheet
and displays it on the userform...no problem. Commandbutton2
executes some code macro2, that reads some user input on the form and
further processes the data. The problem is that macro2 cannot access
variables defined in macro1.

It seemed to me that I could solve this by setting up public
variables, but either I am wrong or am not setting it up correctly.
Can someone please help?
thanks
chuckm


chuckm

Userforms and public variables
 



Thanks,

I think I just solved my problem.

At the top of the Userform code module I added a Public
statement...e.g.
Public MyVariable

Then, at any place in my macros that I need to access MyVariable I do
so by:

x = MyUserform.MyVariable

Seems to work for me

thanks
chuckm


All times are GMT +1. The time now is 10:15 AM.

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