variable not defined issue

RhodEvans

Board Regular
Joined
Oct 31, 2012
Messages
88
Morning,

I'm getting a Variable Not Defined error and would be grateful of some help, or to be pointed in the right direction please.

in my workbook_open I have the following code
Code:
Dim workround As Integer
workround = 0

in one of my sheets worksheet_change I have

Code:
If workround = 0 then

when I get to this I get the Variable not defined error. I am using this to bypass some code that does not always need to be run (it slows the workbook down). So I also have another piece of code that toggles workround from 0 to 1.

I have a feeling this error has something to do with Option Explicit. But My limited understanding is obviously insufficient to know what is happening or how to fix it. As I believe that I have defined the variable within the workbook_open code.

Can anybody help me with this please??
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
If the variable declaration is within your Workbook_Open code, that is the only place it has any meaning - the variable has no scope anywhere else. Move the declaration to the top of a normal module and make it public:
Code:
Public workround As Integer
and you should be fine. (make sure you do not leave the original 'dim' line in the Workbook open code)
 
Upvote 0
Sometimes it's really obvious when someone points it out to you. But thank you very much because I never would have got there on my own!
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

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