Scope of Userform Variable

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
361
Having a blank day

A change event in a combobox increments a counter and then calls a procedure in a module.

The procedure in the module compares the value of the variable with an if statement and if appropriate initiates a msgbox before returning to the userform.

I have declared the counter variable in the module as a Public variable but the variable loses it's value when the called procedure in the module is run.

Have tried to declare the variable as private and global but it doesn't work either.

(y)
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Ziggy12

Did you declared the variable in the Standard module?
 

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
361
Yes, the variable is declared in the standard module.

I also have option explicit declared, and do not get a variable not defined error.

In the userform when the procedure is run the variable is incremented by 1 this can be seen in the watch window but on the jump to the module procedure the variable is still defined but looses the value of 1 and beomes zero.


(y)
 

Forum statistics

Threads
1,137,060
Messages
5,679,376
Members
419,824
Latest member
Mercy kiara

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
Top