In Google Sheets, how can I create an ARRAYFORMULA to generate sequential numbering in column B, only when adjacent C cell is not empty?
Example:
Column B | Column C |
---|---|
1 | apple |
2 | mango |
| |
3 | orange |
4 | peach |
I have found formulas for sequential numbering that ignore blank cells in the adjacent column, but these formulas need to be dragged down whenever new rows are added. I want to use ARRAYFORMULA so that it applies automatically to the entire range.
I tried using this formula generated by Claude:
=ARRAYFORMULA(IF(C10:C<>"", ROW(C10:C) - ROW(C10) + 1, ""))
This formula returns a blank in B cell when the adjacent C cell is empty, but it continues the numbering. So, in the table, it would show 4 - oranges , and , 5 - peach.
Here's one approach which you may adapt accordingly:
=map(C2:C,lambda(Σ,if(Σ="",,counta(C2:Σ))))
Alternative to try just in case those blank cells in Column_C are not true blank cells (which gives ISBLANK(<blank cell>)=false
)
=map(C2:C,lambda(Σ,if(Σ="",,let(Σ,C2:Σ,counta(filter(Σ,Σ<>""))))))