vba - does a boolean variable need to be reset after sub execution?

devofish

Board Regular
Joined
Dec 10, 2016
Messages
68
This may be a dumb question, but just as the question states - I have an argument that prevents the user from using Excel commands forcing the user to use vba cmds to save and/or close. I know a Close will obviously reset everything, but does the variable need to be reset after a Save or does the variable reset after exiting the routine?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
variable resets at end of the sub, UNLESS the variable is a public variable and you are running the sub as a subroutine. if you run a macro and after everything finishes running it will reset.
 
Upvote 0
A macro is a subroutine.
 
Upvote 0
1. Is the variable a public variable
2. are you calling the subroutine multiple times in the main sub
3. are you using the same variable in the main sub

if the answer to 1 is yes and either 2 or 3 is yes, then you should reset it, but otherwise, it think you are ok.
 
Upvote 0
Thank you both! That helps my understanding.

Yes, the variable is public. The variable is set with a command button within the userform. When the userform is unloaded, would that constitute a reset?
 
Upvote 0
Yes if the unloading of the userform is the last step. No, if after it closes the user form, it continues to run other macros. aka it will reset once ALL routine is done running.
 
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