Forum Discussion

Morgul's avatar
Morgul
Copper Contributor
Apr 26, 2025

formula to count cells between same values

hi everyone i am looking for a formula that would count cells between cells with same value for example Column A looking for the number between cells having 2 as value so first answer would be 10 as the next 2 apears 10 cells down then reset and count again and the result would be placed beside the 2 then 9 and so on and the formula would be placed on same sheet but in column C
A           C
2            0         
9            0
15          0
7            0
7            1
9            4
8            0
19          0
7            4
4            0
2            10
3            0
1            0
22          0
8            8
4            6
3            5
9            12
2            8
2            1
8            6
5            0
19          15
1            11
hope someone can help me with that :)
thank you for your interest and time

1 Reply

  • This works best if the data start in A2 (with a header in A1, for example).

    In B2:

    =IFERROR(ROW($A2)-XMATCH($A2, $A$1:$A1, , -1), 0)

    Fill down.

Resources