Compile Error: Variable Not Defined

J

joemeshuggah

i am getting a compile error: variable not defined message on the following
line of code...

FinalRow2009 = Cells(Cells.Rows.Count, "A").End(xlUp).Row

i never had this problem before, and wonder if i may have changed a setting
somewhere and am not sure what needs to be changed to get it to work again.
i tried going into options and unchecking the Require Variable Declaration
box in the Editor tab, but that didn't work.

how do i remedy?

thanks!!!
 
J

Jacob Skaria

Dim FinalRow2009 As Long
FinalRow2009 = Cells(Cells.Rows.Count, "A").End(xlUp).Row

If this post helps click Yes
 
J

Jacob Skaria

Do you have Option Explicit statement on top of the module...

If this post helps click Yes
 
J

Jim Thomlinson

The fix is to declare all of your variables. It is VERY poor coding practice
to not declare your variables.

Dim FinalRow2009 as long

FinalRow2009 = Cells(Rows.Count, "A").End(xlUp).Row

Require variable declarations just inserts the line Option Explicit at the
top of all new code modules. If that line exists in a module then it will
enforce varaible declarations. That is a good thing and it is in ALL well
written code. If option explicit is not included then the compiler will allow
on the fly variables which are a nightmare to debug.
 
P

Patrick Molloy

in the vba development environment (the IDE) from the menu select Tools then
Options
In the Options window, the Editor tab is showing, make sure you check the
'Require Variable Declaration' box - this will then automatically add
OPTION EXPLICIT
to all new modules

before running code, be sure to Debug/Compile too .. thsi will pick up
errors in sybtax or names too
 

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