Option Explicit is ignored

  • Thread starter Michiel via OfficeKB.com
  • Start date
M

Michiel via OfficeKB.com

Anyone can shine a light on this please?

- I start my module with Option Explicit
- In options I also have Require Variable Declaration checked

In my code I use a variable that I did not declare in the Dim section.

Yet, I can still run my code......... without the compliler triggering me
that I forgot to declare the variable.

I do not want this, what should I do to make the option explicit enforced?

Thanks!

M.
 
R

RB Smissaert

Probably you have that variable declared globally (Public) or at module
level (Private). Do a search in your project.

RBS
 
G

Gary Keramidas

i've seen this occasionally. code will run fine, then all of a sudden i get the
error that a variable is not defined. never found out what causes it, as it
doesn't happen very often.
 
M

Michiel via OfficeKB.com

I simplified the code since it was a lot of code.

But in this example it still occurs.

I searched for the variable in other modules but it is not found anywhere

M.

-------------------

Option Explicit
'Constants to define where the columns of interest are in the input file
eSec_Blackrock_SSB 9_10 Breakdown.xls
Const cBAssetCat = 1
Const cBAccount = 2
Const cBCusip = 8

'Constants to define where the columns of interest are in the input file
Security Valuation.xls
Const cVRepAccNo = 1
Const cVMellonSec = 7
Const cVShpPar = 16
Const cVLocalPric = 24
Const cVLocMV = 26

'Constants to define where the columns of interest go in the output report
Const cRRepAccNo = 1
Const cRAssetCat = 2
Const cRMellonSec = 3
Const cRShpPar = 4
Const cRLocalMV = 5
Const cRPArxLocMV = 6


Sub MakeReport()
lngLastSectionRow = ActiveCell.row
Msgbox lngLastSectionRow
End Sub



-------------------

Don said:
As ALWAYS, post your code
Anyone can shine a light on this please?
[quoted text clipped - 11 lines]
 
M

Michiel via OfficeKB.com

I searched (in the whole project) but it is not found.
I have added the extremely simplified code above.


M.


RB said:
Probably you have that variable declared globally (Public) or at module
level (Private). Do a search in your project.

RBS
Anyone can shine a light on this please?
[quoted text clipped - 11 lines]
 
D

Dougaj4

Michiel - I copied and pasted your code (XL 2007) and got an error
message (Variable not defined) at:
lngLastSectionRow = ActiveCell.row

Which version are you using?

I have had some redim statements allowed without a dim in earlier
versions, which 2007 picked up.

Doug
 
B

Barb Reinhardt

I've seen the same thing. Sometimes it works, sometimes it doesn't. Most
of the time it works.
 
M

Michiel via OfficeKB.com

To all who were so kind to respond to my entry.
THANKS!

I think it is indeed the same what Gary and Barb experienced.
When I open a new workbook and drag over my VBA modules into that project and
run the code I do get the error. This seems like some bug to me.

So, THE SOLUTION / WORKAROUND:
- Move the modules to a new workbook
- Pray it will not happen again.

ML.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top