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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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 :roll: , 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,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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