Passing a variable from a UserForm to a Procedure

Herve

Board Regular
Joined
May 6, 2003
Messages
68
Hello All!

I do not succeed to pass a variable (Control Button) from a UserForm to a Procedure (in a regular Module).

I am declaring the variable as Public and Static, but I get a message that VBA does not support this kind of automation.

What's the best way to do that? (I currently save the variable in a cell on a worksheet before unloading the UserForm, then read it from that location when I am back in the Procedure. I figure there must be an easier way :)

Thanks!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Jon Peltier said:
Herve -

I use invisible text boxes and check boxes all the time. Very handy and very sneaky.

- Jon

And very pointless. Variables does the same.
 
Upvote 0
Well, as Jon says, or at least means :rolleyes: , to each his own.

I think however the question is which one is more efficient.

Isn't a Public variable, once declared, reserved in memory whether used or not? Since the TextBox is deleted once the UserForm is closed, aren't we ahead of the game?
 
Upvote 0
Hi,
I would be more than happy if you could help me.

I have to run a macro where, at a certain point, I ask the user to set the variables "capital" and "time".
Here the code for the Userform:

Private Sub CommandButton1_Click()

capital = UserForm1.TextBox1.Value
temp = UserForm1.TextBox2.Value

Me.Hide

End Sub


In the main code of the macro I have just written:

UserForm1.Show

But is not working. VBA can't read the variables' values, so the routine does not work.
I really do not know what to do.
I am stuck on this stupid thing and cannot go ahead.
If you could help me I would be pleased.
Thank you!
D
 
Upvote 0

Forum statistics

Threads
1,215,892
Messages
6,127,610
Members
449,389
Latest member
ChessManNaill

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top