How can I find the last row in a range of cells that hold a formula, where the result of the formula is an actual value and not empty?
Say in a simplified way that
You want to find the last cell in a column that is not empty AND is not a blank string("").
Just follow the LastRow with a loop checking for a non-blank cell.
lastrow = ActiveSheet.Range("E" & ActiveSheet.Rows.Count).End(xlUp).Row
Do
If ActiveSheet.Cells(lastrow, 5).Value <> "" Then
Exit Do
End If
lastrow = lastrow - 1
Loop While lastrow > 0
If lastrow > 0 Then
Debug.Print "Last row with data: " & lastrow
Else
Debug.Print "No data in the column"
End If
Notice that your Rows.count
does not specify which sheet. That means it will use the active sheet. Of course ActiveSheet.Range()
also is on the active sheet. But it is bad practice to mix Range
or Rows
with .Range
or .Rows
. It indicates a thoughtless usage that could bite you if you changed the ActiveSheet
but didn't change the unspecified reference.