I need a formula to locate the last used cell in a block. By last used cell I mean:
- Locate the last column (right-most) containing non-null data
- Locate the lowest cell in that column that contains non-null data
- Return the address of that cell
For example, in the block B2:I16:
The function should return: I15 rather than D16. I already have a VBA UDF that I am trying to replace:
Public Function FindLast(r As Range) As String
Dim nLastRow As Long, nLastColumn As Long
Dim nFirstRow As Long, nFirstColumn As Long
Dim i As Long, j As Long
nLastRow = r.Rows.Count + r.Row - 1
nLastColumn = r.Columns.Count + r.Column - 1
nFirstRow = r.Row
nFirstColumn = r.Column
For i = nLastColumn To nFirstColumn Step -1
For j = nLastRow To nFirstRow Step -1
If Len(r(j, i)) > 0 Then
FindLast = r(j, i).Address(0, 0)
Exit Function
End If
Next j
Next i
End Function
As the worksheet must work in a macro-free environment.