Consecutive Values

Fyldeboy

New Member
Joined
Oct 21, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
I have 7 columns representing days of the week, they each contain a 0 or 1 to indicate if the person is working that day.
I need to create an array formula to measure how many days worked (1) until they have a day off - so number of consecutive 1s until 1st 0.
I also need to calculate how many 1s from the last 0 to the end of the row.
Staff​
Mon​
Tue​
Wed​
Thu​
Fri​
Sat​
Sun​
start​
end​
GD​
1​
1​
1​
0​
0​
1​
1​
3​
2​
DR​
0​
1​
1​
0​
1​
1​
1​
0​
3​
MD​
0​
1​
1​
1​
1​
1​
0​
0​
0​
DLH​
1​
0​
1​
1​
1​
0​
1​
1​
1​
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi Fyldeboy,

Does this do what you ask?

Fyldeboy.xlsx
ABCDEFGHIJ
1StaffMonTueWedThuFriSatSunstartend
2GD111001132
3DR011011103
4MD011111000
5DLH101110111
Sheet2
Cell Formulas
RangeFormula
I2:I5I2=IF(B2=0,0,MATCH(0,C2:H2,0))
J2:J5J2=7-MATCH(2,1/(B2:H2=0))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Thanks so much. Weirdly, that seemed to work on the 1st row but not afterwards. I certainly can't understand why rows 17/18 don't return 0, even I can see its a simple if statement!

1603350977175.png
 
Upvote 0
slight ammendment to the image above - with formula done as Ctrl, Shift, Enter

1603351369213.png
 
Upvote 0
Check that you're using the numeric 0 and not alphabetic o because they appear different on the image:
1603362722921.png
 
Upvote 0
@Toadstool
Subject to my question below, your I2 formula could just be ..
Excel Formula:
=MATCH(0,B2:H2,0)-1

@Fyldeboy
Is it possible that somebody could work all 7 days?

If so, the amendment to my formula above would be (adjusted for your actual range of course)
Excel Formula:
=IFNA(MATCH(0,B2:H2,0)-1,7)

.. and Toadstool's other formula might become
Excel Formula:
=7-IFNA(MATCH(2,1/(B2:H2=0)),0)
 
Upvote 0
Solution
You guys are amazing, it was some 0/O error, though the issue of them looking differently was just do do with them being formatted differently.
 
Upvote 0
Glad you got it sorted - thanks to Toadstool's keen eyesight. (y)
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,667
Members
449,045
Latest member
Marcus05

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