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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

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,460
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,834
Messages
5,855,901
Members
431,772
Latest member
dannyboi1

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
Top