How to find the true Last Cell in any Worksheet

前端 未结 5 1936
遇见更好的自我
遇见更好的自我 2021-01-13 01:12

This question is now answered elegantly, thanks to Chris Neilsen, see the answer below. It is the one I will use from now on. The solution reliably finds the last cell in

5条回答
  •  一个人的身影
    2021-01-13 01:53

    I think you can utilize the .UsedRange property from the Worksheet object. Try below:

    Option Explicit
    
    Function GetTrueLastCell(WS As Worksheet) As Range
        With WS
            If .UsedRange.Count = 1 Then
                Set GetTrueLastCell = .UsedRange
            Else
                Set GetTrueLastCell = .Range(Split(.UsedRange.Address, ":")(1))
            End If
        End With
    End Function
    

提交回复
热议问题