using Findas shown below is useful
- can immediately find the last (or first) cell in the 2D range
- testing
Nothingmeans a space - will work in a range that cannot be adjacent (i.e. a range
SpecialCells)
change "YourSheet"to the name of the sheet you are looking for
Sub Method2()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Sheets("YourSheet")
Set rng1 = ws.Columns("A:B").Find("*", ws.[a1], xlValues, , xlByRows, xlPrevious)
If Not rng1 Is Nothing Then
MsgBox "last cell is " & rng1.Address(0, 0)
Else
MsgBox ws.Name & " columns A:B are empty", vbCritical
End If
End Sub
source
share