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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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