Solved

Get the last row for a apecific column

Posted on 2011-03-18
5
485 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 125 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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

860 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