Tuesday, February 2, 2016

Excel VBA- Last used cell in the sheet

EXCEL VBA TO FIND THE LAST CELL IN AN ACTIVE SHEET

Method I

Sub pLastCell()

    ActiveWorkbook.Save
    Debug.Print ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Address
    
End Sub


Method II

Sub pLastCelllValue()

    Dim lastRow As Long
    Dim lastCol As Long
    ''Reset the Used Range
    ActiveSheet.UsedRange
    
    With ActiveSheet.UsedRange
        lastRow = .Rows.Count
        lastCol = .Columns.Count
    End With
    
    Debug.Print ActiveSheet.Cells(lastRow, lastCol)
    
End Sub

No comments:

Post a Comment

Hot Topics