help me please with variables

slim

New Member
Joined
Feb 24, 2002
Messages
42
is it possible to carry the value of a variable defined in one user form into another user form?
I can do it across modules using the 'public' declaration

public myvariable as string

the variable retains its value in a different module no problem.

Do the same in a form (setting the variable by taking the value of a text box) and its fine until I switch to the next user form where the variable is empty! This is really bugging me!

Anyone able to help, simple code available if needed.

Andy
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you have two UserForms with textboxes, then you can refer to the textbox on the other form from within the form module as follows: -

TextBox1.Text= UserForm2.TextBox.Text

If that doesn't help, consider hiving off anything that deals with variables into a normal module procedure, called in response to an event on your UserForm.

As a simple example if you press command button 1 on your first UserForm, then call your procedure from that click event, assign the textbox value (say) to your variable and do your manipulation within the standard module. Hope that helps, if you post more specifics, then I could give you some more advice.
 
Upvote 0
From what I understand you need to create a public variable in a module sheet and assign it to be equal to the text box then when the new user form is needed assign the text box in this to be equal to the public variable in the module.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,114,002
Members
448,543
Latest member
MartinLarkin

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