DeleteBottomRowsFromWorksheet

Note: This method depends on GetLastUsedRowNumberInWorksheet

Sub DeleteBottomRowsFromWorksheet( _
    ws As Worksheet _
)
    Dim _
        strStartingEmptyRow As String, _
        rngStartingRow As Range, _
        rngEmptyRows As Range, _
        lngLastRow As Long
    lngLastRow = _
        GetLastUsedRowNumberInWorksheet( _
            ws _
        )
    If lngLastRow = _
        -1 Then
        Exit Sub
    End If
    strStartingEmptyRow = _
        CStr( _
            lngLastRow + 1 _
        )
    Set rngStartingRow = _
        ws.Rows( _
            strStartingEmptyRow & _
            ":" & _
            strStartingEmptyRow _
        )
    Set rngEmptyRows = _
        Range( _
            rngStartingRow, _
            rngStartingRow.End( _
                xlDown _
            ) _
        )
    rngEmptyRows.Delete _
        shift:=xlUp
End Sub

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *