Countif unless value present, then start count over

brandon20

Board Regular
Joined
Feb 12, 2014
Messages
203
Hi,

I need to count how many times a rig occurs in my spreadsheet in consecutive order,
I currently have a countif equation that works for this.
I wanted to add an argument so the function will not count if there is a start value present in column B BUT I also need the function to start the count over for this rig.

I have shown an example of what I am looking for below.

Thanks


RigStartCountif
A5/1/2015=COUNTIF($A$2:A2,A2)
B1
C1
D1
A2
B2
C2
D2
A3
B3
C3
D3

<colgroup><col><col><col></colgroup><tbody>
</tbody>


Example of what I am looking for
RigStartCountif
A5/1/2015RR
B1
C1
D1
A1
B2
C2
D2
A2
B3
C3
D3

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Does this help?


Excel 2010
ABCDE
1RigStartCountifDesiredFormula
2A05/01/20151RRRR
3B111
4C111
5D111
6A211
7B222
8C222
9D222
10A06/01/20153RRRR
11B333
12C333
13D333
14A411
15B444
16C444
17D444
18A522
19B555
20C555
21D555
Sheet1
Cell Formulas
RangeFormula
E2=IF(B2>0,"RR",COUNTIFS($A$2:A2,A2,$B$2:B2,"")-MAX(COUNTIFS($A$2:A2,A2,$B$2:B2,">0")-1,0))
 
Upvote 0
Hi,

Thanks! that almost works,
but it seems to subtract values as more start dates add to the sheet
I need this to just start at 1 again once a start date is added
I gave an example of what of what i would desire.

Thanks!






RigStartDesiredFormula
A5/1/2015RRRR
B11
C11
D11
A6/1/2015RRRR
B22
C22
D22
A7/1/2015RRRR
B33
C33
D33
A1-1
B44
C44
D44
A20
B55
C55
D55
A31
B66
C66
D66

<colgroup><col><col><col span="3"></colgroup><tbody>
</tbody>
 
Upvote 0
I need to get better at this stuff. This doesn't look very nice and there is probably a better way but this seems to work:


Excel 2010
ABCD
1RigStartDesiredFormula
2A05/01/2015RRRR
3B11
4C11
5D11
6A06/01/2015RRRR
7B22
8C22
9D22
10A07/01/2015RRRR
11B33
12C33
13D33
14A11
15B44
16C44
17D44
18A22
19B55
20C55
21D55
22A33
23B66
24C66
25D66
Sheet2
Cell Formulas
RangeFormula
D2=IF(B2>0,"RR",COUNTIF($A$2:A2,A2)-IFERROR(COUNTIF(OFFSET($A$1,0,0,SUMPRODUCT(MAX(($A$2:A2=A2)*ROW($A$2:A2)*($B$2:B2<>""))),1),A2),0))
 
Upvote 0
Thanks! not that I understand how it works though. haha.
OFFSET and SUMPRODUCT are confusing to me. I will attempt to reverse engineer this to see how it functions.
I added another layer to the equation, now I have start and end dates, it works perfectly for what I am trying to do. (at the moment). Thanks again!


RigstartEndFormula
A5/10/20155/25/2015RR
B5/20/20155/29/2015RR
C1
D1
A6/1/20140
B1
C2
D2
A1
B2
C3
D3
A2
B3
C4
D4
A3
B4
C5
D5

<colgroup><col width="157" span="4" style="width:118pt"> </colgroup><tbody>
</tbody>




=IF(C2>0,"RR",IF(B2>0,0,COUNTIF($A$2:A2,A2)-IFERROR(COUNTIF(OFFSET($A$1,0,0,SUMPRODUCT(MAX(($A$2:A2=A2)*ROW($A$2:A2)*($B$2:B2<>""))),1),A2),0)))

<tbody>
</tbody>
 
Upvote 0
I'm glad it works, but it's by no means the only answer I'm sure.

Example using Rig = A

Count all the values of A up to the formula row. (Count1)

The sumproduct finds the last row where column B is not blank (has a date) up to the row containing the formula.
The Offset creates a range starting in A1 and finishing at the row found by sumproduct.
Count all the values of A in this new range. (Count2)

The Formula result is Count1 - Count2
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,795
Members
449,468
Latest member
AGreen17

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