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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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)
 
Upvote 0
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)
 
Upvote 0
great thanks for the tip...I think that will work great. Any Idea if that will make the macro slow?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top