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??
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,349
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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)
 

RhodEvans

Board Regular
Joined
Oct 31, 2012
Messages
88
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!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,349
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Always glad to help. :)
 

Forum statistics

Threads
1,082,141
Messages
5,363,368
Members
400,731
Latest member
Jackserver

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top