LastRow = Selection.Row(Compile Error: Variable not defined)

DeanC

New Member
Joined
Jan 12, 2004
Messages
10
Dear All,

I am trying to set the last row of data to a variable LastRow, which I have used many times before successfully! However, it just doesn't want to work on my current Macro and I get a compile error?

(Compile Error: Variable not defined)

(Has this beginner obviously missed something or inadvertantly flagged someing to hinder his progress?) Code to follow!

Code:
Range("A17").Select
    ActiveCell.End(xlDown).Select
    LastRow = Selection.Row

Any thoughts?
javascript:emoticon(':oops:')
Bang head
Many thanks!
Dean
[/i]
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Re: LastRow = Selection.Row(Compile Error: Variable not defi

Hi Dean, this error occurs when you have used a variable but havent declared it prior to using the variable. Declare means using the DIM keyword to define the variable name and its type. I suspect you have a line that has Option Explicit in your module where you didnt before. This enforces declaring variables. You can remove this line, or declare the variable & IMHO you should declare variables as its good programming practice.

Code:
Option Explicit

Sub Test()
Dim LastRow As Long
Range("A17").Select
    ActiveCell.End(xlDown).Select
    LastRow = Selection.Row
End Sub
 
Upvote 0
Re: LastRow = Selection.Row(Compile Error: Variable not defi

Thank-you Parry

I don't know how I flagged Option Explicit but It gives me something to look into tonight!

Have tried your code ...I'm back on track!

Many, many Thanks!


Regards
Dean
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,268
Members
448,558
Latest member
aivin

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