Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get the last row for a apecific column

Posted on 2011-03-18
5
Medium Priority
?
507 Views
Last Modified: 2012-06-22
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

0
Comment
Question by:zhshqzyc
  • 3
5 Comments
 
LVL 18

Accepted Solution

by:
Curt Lindstrom earned 500 total points
ID: 35165073
Try this:

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

Curt
0
 
LVL 4

Expert Comment

by:sgvill
ID: 35165102
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

0
 
LVL 18

Expert Comment

by:Curt Lindstrom
ID: 35165108
Or

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

if Excel 2003

The first one was for 2007 or later

Curt
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 35165524
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
0
 
LVL 18

Expert Comment

by:Curt Lindstrom
ID: 35169497
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question