Home

Consulting

Excel VBA

Legal

Links

Contact

About Us

Find Last Row With Specified Column

'********************************************************************
'  http://www.KravatzInc.com    1-866-XLS-PROG
'
'  This code is copyrighted by Kravatz, Inc. (c) 2007 All Rights Reserved.
'  You may use this code as long as this message appears
'  There is no warranty made to the fitness or suitablilty of this code
'  and by using it you hold Kravatz, Inc. harmless for any damages
'  that may result from its use.  This code is supplied as is.
'  
'********************************************************************
Function FindLastRow(c As Long) As Long
 
'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
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

    If ActiveCell.Row = prevRow Then
        FindLastRow = ActiveCell.Row
        Exit Function
    Else
        prevRow = ActiveCell.Row
    End If
    
Loop
 
FindLastRow = ActiveCell.Row
 

End Function