Find the last not empty row in a range of cells holding a formula

后端 未结 4 1537
轮回少年
轮回少年 2021-01-12 03:11

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

4条回答
  •  情书的邮戳
    2021-01-12 03:48

    I think that more elegant way than was provided by @D_Bester is to use find() option without looping through the range of cells:

    Sub test()
        Dim cl As Range, i&
        Set cl = Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
        i = cl.Find("*", , xlValues, , xlByRows, xlPrevious).Row
        Debug.Print "Last row with data: " & i
    End Sub
    

    test

    Also, more shorter version of the code which was provided above is:

    Sub test2()
        Debug.Print [E:E].Find("*", , xlValues, , xlByRows, xlPrevious).Row
    End Sub
    

提交回复
热议问题