Solved

Get the last row for a apecific column

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now