Link to home
Start Free TrialLog in
Avatar of zhshqzyc
zhshqzyc

asked on

Get the last row for a apecific column

I want to get column A's last row. Am I right?

Function xlCellTypeLastRow()
    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
    End With
    xlCellTypeLastRow = LastRow
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Curt Lindstrom
Curt Lindstrom
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sgvill
sgvill

It might work, but I have read that Excel doesn't keep track very well sometimes.   Here is another way:

LastRow = Range("A65536").End(xlUp).Row

Open in new window

Or

xlLastRow = Ws.Range("A32768").End(xlUp).Row

if Excel 2003

The first one was for 2007 or later

Curt
Actually, for it to work on excel 2007 or later, it would have to be:
xlLastRow = Ws.Range("A1048576").End(xlUp).Row

A65536 is for 2000-2003.

One other simple option is:

xlLastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Cluskitt,

Of course it is! I confused my self using a 2003 file in 2007. I think added that post too late at night. Thanks for correcting me!

Cheers,
Curt