Scope of Userform Variable

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
365
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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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)
 
Upvote 0

Forum statistics

Threads
1,216,481
Messages
6,130,922
Members
449,606
Latest member
jaybar0812

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