By using t2do.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

FindLastRow

Function FindLastRow(c As Long) As Long
'Version: 1.001
'Purpose: This routine will find the last row in the spread sheet for the passed column
' c is the column to use to find the last row
' ignore's hidden rows
'1.001 didn't work if formula set cell to a blank

Dim prevRow As Long

'Go to the end
On Error Resume Next
Cells(Cells.Rows.Count, c).Select '
If Err <> 0 Then
    FindLastRow = 0
    Exit Function
End If

Selection.End(xlUp).Select
prevRow = 0
Do While Trim(ActiveCell.Text) = "" And ActiveCell.Row <> 1
'    Selection.End(xlUp).Select
    ActiveCell.Offset(-1, 0).Select
    
    
    If ActiveCell.Row = prevRow Then
        FindLastRow = ActiveCell.Row
        Exit Function
    Else
        prevRow = ActiveCell.Row
    End If
    
Loop

FindLastRow = ActiveCell.Row


End Function