Find Last Row ignore formulas

ejs7597

New Member
Joined
Sep 25, 2006
Messages
35
I need help finding the last row in a worksheet. I have wrote vba code several ways, and all of the ways find the last row for me, but it finds the last row that contains a formula. I need to ignore the formula, and only find the last row that actually contains a value that the formula is generating.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
depending on your data size it might not be the most efficient solution but it might help

Code:
Sub FindLast()
Dim lastRow As Long
lastRow = Range("A" & Rows.Count).End(xlUp).Row

Dim found As Boolean: found = False

While Not found And Not lastRow = 1
    If Range("A" & lastRow).Value = "" Then
        lastRow = lastRow - 1
    Else
        found = True
    End If
Wend

MsgBox lastRow

End Sub
 
Upvote 0
Hi,

You can find the last row with a value using FIND.
Code:
Sub test()
Dim LR As Long
    With ActiveSheet.Cells
    LR = .Find("*", .Cells(1, 1), xlValues, xlPart, xlByRows, xlPrevious, False, False).Row
    End With
    
MsgBox "Last row with data is " & LR, vbOKOnly, "REPORT"
End Sub
kind regards,
Erik
 
Upvote 0
Not sure if this is the best way but it might help:

Code:
Sub test()
Dim lastRow As Long, myRow As Long
lastRow = Range("A65536").End(xlUp).Row
For myRow = lastRow To 2 Step -1
    If Cells(myRow, 1).HasFormula = False Then
        MsgBox Cells(myRow, 1).Address & " is last value"
    Exit Sub
End If
Next myRow
End Sub

Dom
 
Upvote 0
Thanks for all of your help. I used Erik's code, remarked out the msgbox, and added ActiveSheet.PageSetup.PrintArea = "$A$1:$I$" & LR
to set my printarea correctly.
Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

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