How to count until a certain value?

CHeiring

New Member
Joined
Apr 4, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a spreadsheet in which I have a Column in which a "1" indicated the beginning of a section of time and "2" indicates the end of this section.

I would like to be able to from top to bottom to go through column A (see Image), and the count the number of rows between the first time a cell contain "1" until a cell contains "2" - number of rows will equal duration. It should then continue for every "1" and "2". The result = number of rows between each "1" and "2" pair should show in column B. In Column C I have shown how I would like the results to be presented.

Is this possible to do in Excel with formulas?

1680600097952.png



Many thanks in advance

Cheers

Christian
 
Both the formulae posted here will return numbers & not text.
Yes - I messed up. I have an if statement where I accidentally combined the formula to write 1 (as a number) if true but "" if false. When changing to "" to 0 (as a number) problem disappeared :)
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,453
Messages
6,124,918
Members
449,195
Latest member
Stevenciu

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