Find End of Data

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
I am looking to find the end of the data in my worksheet. The end is ALWAYS a "Report Total" cell in column A:A. I want to find this cell and move down a space or two. The problem is there are going to be multiple "Report Total" cells and also multiple BLANK cells. Someone said to use the following but I am not sure how to use it.


Dim lastRow As Long
Dim lastRowE As Long

lastRow = Cells.Find("Report Total", searchdirection:=xlPrevious).Row
lastRowE = Range("A:A").Find("Report Total",_ searchdirection:=xlPrevious).Row
lastRowE = Range("A" & Rows.Count).End(xlUp).Row


I am not sure how this will work. In the code the "searchdirection" that is there, how will this be replaced? With a "UP", "DOWN", or "xlUP", "xl"Down"?

Thanks for all the help
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Fat Cat

Active Member
Joined
Nov 5, 2004
Messages
336
Try looking from the bottom of column A upwards

eg;
Code:
Dim LastRow As Long

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

MsgBox("The last used row in column A is " & LastRow)
 

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,459
If it is at the bottom of column A, try:

lastrow = range("A" & [a65536].end(xlup).row)

or to offset:
lastrow = range("A" & [a65536].end(xlup).row).offset(2,0)
 

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
great thanks for the tip...I think that will work great. Any Idea if that will make the macro slow?
 

Fat Cat

Active Member
Joined
Nov 5, 2004
Messages
336
I wouldn't think it will slow it down measurably at all.

For interest, doing a single search takes no time at all, repeating the search 100,000 times only takes 8 seconds

Code:
Private Sub CommandButton1_Click()

Dim LastRow As Long
Dim StartTime As Date
Dim EndTime As Date
 
StartTime = Now()
For i = 1 To 100000
    LastRow = Range("A65536").End(xlUp).Row
Next i

EndTime = Now()
MsgBox ("The time it took was " & Format(EndTime - StartTime, "hh-mm-ss"))

End Sub
 

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
thats a cool tool you built. thanks again to all for sharing your knowledge.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,799
Messages
5,574,380
Members
412,589
Latest member
ArtBOM
Top