counting consecutive days worked.....

chris_sweezy

New Member
Joined
Aug 25, 2018
Messages
14
Trying to count employee's consecutive days worked (no more than 13, 14th has to be a rest day). Problem is.. count should restart after an absence.


8/18/28/38/48/68/78/8
Consecutive Days Worked InInInInInInIn
1110111
1101011
0000000
1111111
1100111
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This is dead easy using a formula if the data is arranged down a single column, and much harder in a table.

You could select the range of interest and run this (perhaps from a shortcut key):

Code:
Sub TooManyDays()
  Dim r             As Range
  Dim cell          As Range
  Dim n             As Long

  Set r = ActiveWindow.RangeSelection
  r.Interior.Color = vbWhite

  For Each cell In r
    Select Case True
      Case IsEmpty(cell.Value)
        cell.Interior.Color = vbYellow
      Case cell.Value = 1
        n = n + 1
        If n > 13 Then cell.Interior.Color = vbRed
      Case cell.Value = 0
        n = 0
      Case Else
        cell.Interior.Color = vbYellow
    End Select
  Next cell
End Sub

For example,

A​
B​
C​
D​
E​
F​
G​
1​
In
In
In
In
In
In
In
2​
1​
1​
1​
1​
1​
1​
1​
3​
1​
1​
1​
1​
1​
1​
1​
4​
0​
1​
1​
1​
1​
1​
1​
5​
0​
1​
1​
1​
1​
1​
1​
6​
1​
0​
0​
1​
1​
1​
1​
7​
1​
1​
1​
1​
1​
1​
1​
8​
1​
0​
1​
1​
1​
1​
1​
9​
1​
1​
1​
1​
1​
1​
1​
10​
1​
1​
1​
1​
1​
1​
0​
11​
1​
1​
1​
1​
1​
0​
1​
12​
1​
0​
1​
1​
1​
1​
1​
13​
1​
0​
0​
1​
1​
1​
1​
14​
1​
0​
1​
1​
1​
1​
1​
15​
1​
1​
1​
0​
1​
1​
1​
16​
1​
1​
1​
1​
1​
1​
1​
17​
1​
1​
1​
0​
1​
1​
0​
18​
1​
1​
1​
1​
1​
1​
1​
19​
1​
1​
1​
1​
1​
1​
1​
20​
1​
1​
0​
1​
1​
1​
1​
21​
1​
1​
1​
0​
0​
1​
1​
22​
1​
1​
1​
1​
1​
1​
1​
23​
1​
1​
1​
0​
1​
1​
1​
 
Upvote 0
this is a VBA code and you need to use alt f11
Insert module
 
Upvote 0
Here is a better look at my data... I should have sent better look initially. Might help?
8/18/28/38/48/68/78/88/98/108/118/128/13
EMPLOYE E NUMBER
EMPLOYEE NAME
CLASS
RATE
Consecutive Days Worked
In
InInInInInInInInInInIn
APA6128ALL, DAVID "RANDY" GF #111011111111
APA0430ALVARADO, JOSE ANGEL Lead # 110101111111
APA8155ARDOIN, BRANDON Lead # 000000000000
APA0057ARRIAGA MORALES, JUAN Carpenter # 111111111111
APA1964BARULICH, NICHOLAS GF # 110011111111
APA9168BOLDEN, KENNETH Lead # 111111111111
<colgroup><col width="58" style="width: 43pt; mso-width-source: userset; mso-width-alt: 2304;"> <col width="61" style="width: 46pt; mso-width-source: userset; mso-width-alt: 2432;"> <col width="34" style="width: 25pt; mso-width-source: userset; mso-width-alt: 1344;"> <col width="15" style="width: 11pt; mso-width-source: userset; mso-width-alt: 608;"> <col width="69" style="width: 52pt; mso-width-source: userset; mso-width-alt: 2752;"> <col width="30" style="width: 22pt; mso-width-source: userset; mso-width-alt: 1184;" span="12"> <tbody> </tbody>
 
Upvote 0
Here is a better look at my data... I should have sent better look initially. Might help?
8/18/28/38/48/68/78/88/98/108/118/128/13
EMPLOYE E NUMBEREMPLOYEE NAME CLASS RATE Consecutive Days Worked InInInInInInInInInInInIn
APA6128ALL, DAVID "RANDY" GF #111011111111
APA0430ALVARADO, JOSE ANGEL Lead #110101111111
APA8155ARDOIN, BRANDON Lead #000000000000
APA0057ARRIAGA MORALES, JUAN Carpenter #111111111111
APA1964BARULICH, NICHOLAS GF #110011111111
APA9168BOLDEN, KENNETH Lead #111111111111

<tbody>
</tbody>

I apologize, I'm new at this.... This counting of consecutive days worked will be from whatever the current date is, looking back. Also, each column header is a date... above the "In".
Thanks for your patience and help.
 
Upvote 0
Can anyone please have a look? I've searched and searched, found a couple that ALMOST accomplishes what's needed
 
Upvote 0
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
M​
N​
O​
P​
Q​
1​
#
Name
Class
Rate
Cons
In
In
In
In
In
In
In
In
In
In
In
In
2​
APA6128AlanGF #
8​
1​
1​
1​
0​
1​
1​
1​
1​
1​
1​
1​
1​
3​
APA0430BarbLead #
7​
1​
1​
0​
1​
0​
1​
1​
1​
1​
1​
1​
1​
4​
APA8155CainLead #
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
5​
APA0057DanaCarpenter #
12​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
6​
APA1964EricGF #
8​
1​
1​
0​
0​
1​
1​
1​
1​
1​
1​
1​
1​
7​
APA9168FranLead #
12​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
In E2, confirmed with Ctrl+Shift+Enter,

=MAX(FREQUENCY(IF(F2:Q2=1, COLUMN(F2:Q2)), IF(F2:Q2<>1, COLUMN(F2:Q2))))
 
Upvote 0
SHG , thanks so much for taking your time to help me. I am really appreciative. I copy & paste, hit Ctrl+Shift+Enter, but it doesn't work. Would it be possible making it count the 13 days from present date? It will change everyday.... Again, thanks.
 
Upvote 0
Paste the formula in the formula bar, press and hold the Control and Shift keys, then press Enter.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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