Count number of rows until a value is reached

ondi58

New Member
Joined
Dec 13, 2018
Messages
4
Hi, I've been searching for an answer to this for a while but can't work it out, so I'm calling for help!

(BTW, I'm using Google Sheets)

I've a list of football results, and I'm trying to calculate the longest unbeaten run. Column A shows the result (Won, Lost, Drawn). I'd like column B to increase by 1, for every row until a "Lost" is reached. The "Lost" resets the counter to 0.

Here is an example of what the outcome should be.

AB
Won1
Won2
Drawn3
Drawn4
Lost0
Lost0
Won1
Lost0
Won1
Drawn2

<tbody>
</tbody>


Thank you so much in advance!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You have to start this in row 2... so use headers in your columns.

=IF(A2="Lost",0,B1+1)
 
Last edited:
Upvote 0
That's perfect, thank you!

Would you know how to do the same, but for the same value to repeat - so the number of times "Won" appears in a row, resetting to 0 when "Drawn" or "Lost" appears. I've tried with this formula, but without luck.

Code:
[COLOR=#000000][FONT=Inconsolata]=[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]IF[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]([/FONT][/COLOR][COLOR=#F7981D][FONT=Inconsolata]I3[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]=[/FONT][/COLOR][COLOR=green][FONT=Inconsolata]"Won"[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata],[/FONT][/COLOR][COLOR=#7E3794][FONT=Inconsolata]J1[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]+[/FONT][/COLOR][COLOR=#1155CC][FONT=Inconsolata]1[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata],[/FONT][/COLOR][COLOR=#1155CC][FONT=Inconsolata]1[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata])[/FONT][/COLOR]

(cell references changed for my spreadsheet)

Many thanks
 
Upvote 0
Thank you. However, it's showing the result one row below the last "Won"

Here's what it's showing

Drew0
Lost0
Won0
Won1
Lost2
Lost0
Won0
Lost1

<tbody>
</tbody>

Here's what I'd like it to show:

Drew0
Lost0
Won1
Won2
Lost0
Lost0
Won1
Lost0


<tbody>
</tbody>

Thanks again so much for your help
 
Upvote 0
You havent said which row the formula is in. Thats the crucial bit. The I2 needs to be the cell to the left of the formula. The J1 needs to be the cell above the formula. Change the 2 and 1 to suit.
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top