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

后端 未结 4 1536
轮回少年
轮回少年 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 04:03

    This should help you determine the last row containing a formula (in column A on sheet1 Sheet1):

    lastRow  = Split(Split(Sheet1.Range("A:A").SpecialCells(xlCellTypeFormulas).Address, ",")(UBound(Split(Sheet1.Range("A:A").SpecialCells(xlCellTypeFormulas).Address, ","))), "$")(2)
    

    SpecialCells is used to determine the range of all the cells containing a formula. This range is then parsed using Split. With Ubound the last of these cells is being retrieved. The result is being split again to extract the row number.

提交回复
热议问题