Determine last non-value (may have a formula) row in column

前端 未结 4 1369
一向
一向 2021-01-22 13:59

I have a column that has a formula in each row field. The formula propagates data from another Excel spreasheet. If there is nothing in the row field, though, the row remains bl

4条回答
  •  一生所求
    2021-01-22 14:43

    Please follow below code.

    Sub Test()
        Dim i As Long, tempLast As Long, lastRow As Long
        tempLast = Range("C" & Rows.Count).End(xlUp).Row
    
        For i = 1 To tempLast
              If Cells(i, 1).HasFormula Or Not Cells(i, 1).HasFormula Then
                 If Len(Cells(i, 1).Value) < 1 Then
                    lastRow = i
                    Exit For
                End If
            End If
        Next
    
        MsgBox lastRow
    End Sub
    

提交回复
热议问题