?
Solved

Get the last row for a apecific column

Posted on 2011-03-18
5
Medium Priority
?
502 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

719 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