Last cell in column

P

Paul Wilson

Hi,

I just wanted to find out the number of rows based on the last cell which
has data.

I have been trying to use the following

Dim LastCell As Double
LastCell = Cells(Rows.Count, 5).End(xlUp)

But get a VBA error.
 
G

Gary Keramidas

you need .row after your statement you should also use long instead of
double and qualify the range. you can also use the column letter if it makes
it easier.

Dim LastCell As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
LastCell = ws.Cells(Rows.Count, "E").End(xlUp).Row
 
G

Gary Keramidas

one other thing i wanted to add but forgot,

this line:
LastCell = ws.Cells(Rows.Count, 5).End(xlUp)
would not have errored if you had a number in the "lastcell" because it was
dimmed as double. "lastcell" would have been = to the value of that last cell if
you dimmed it as long or variant or some other type that can hold whatever was
stored in that cell.
 

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