My apologizes, the range is u4:u1003 and not in the T column.
Also, when I change the formula to =countformulaegt(U4:U1003,20)
the function code gave a result of 230, the desired result should be 5.
Below are the cell contents in the formula bar:
cell contents
u4==IF(T4="Y","x",IF((T4="N")*(T2="Y"),1,U2+1))
u5==IF(T5="Y","x",IF((T5="N")*(T4="Y"),1,U4+1))
u6==IF(T6="Y","x",IF((T6="N")*(T5="Y"),1,U5+1))
u7==IF(T7="Y","x",IF((T7="N")*(T6="Y"),1,U6+1))