My X-No working day in the weekend (without offs, holidays, sick leaves etc)

songo

New Member
Joined
Apr 16, 2015
Messages
15
Hello guys,


I am trying to figure out formula that will show number of my work day in week, I don't have standard schedule.
Instead i can work Mon,Tue,OFF,Thu,Fri,OFF,Sun or it can be: Mon,OFF, Tue, HOLIDAY,OFF, Fri,Sat,Sun.
Networkday - only counts total days, workday - also doesn't give what i want.


Like on the table below, 2nd column is final result of formula what i am trying to acomplish.

Monday1
Tuesday
2
Wednesday3
OFF
Friday4
OFF
Sunday5
Monday1
HOLIDAY
Wednesday2
Thurday3
OFF
OFF
Sunday4
Monday1

<tbody>
</tbody>
etc...
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Assuming your list of days, Off and Holidays is in Column A starting at Row 1, put 1 in cell B1 and then put this formula in cell B2 and copy it down to the end of your list...

=IF(LEFT(A2,3)="Mon",1,IF(OR(LEFT(A2,3)={"OFF","HOL"}),"",LOOKUP(8,B$1:B1)+1))
 
Upvote 0
Thanks Rick for your quick reply!
Please help me with update of this formula, this formula will be used for many people and each month will be separate Sheet,
therefore I can’t put manually 1 on Monday, sometimes 1st day of the month might be Holiday or OFF, so 1st working day will be Tue or etc.
Actual time attendance schedule is as below:

DateStatusMy work day in week
01.09.2017WORK1
02.09.2017OFF
03.09.2017WORK2
04.09.2017OFF
05.09.2017WORK1
06.09.2017HOLIDAY
07.09.2017WORK2
08.09.2017WORK3
09.09.2017OFF
10.09.2017WORK4
11.09.2017OFF
12.09.2017OFF
13.09.2017WORK1
14.09.2017WORK2
15.09.2017WORK3
16.09.2017WORK4
17.09.2017WORK5

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
I could not think of a formula (at least not one that looked like it might go on forever), so I developed a macro for you to use...
Code:
Sub WorkDayEnumerator()
  Dim R As Long, N As Long, Data As Variant, Result As Variant
  Data = Range("A2", Cells(Rows.Count, "B").End(xlUp))
  ReDim Result(1 To UBound(Data), 1 To 1)
  N = 1
  For R = 1 To UBound(Data)
    If Weekday(Data(R, 1)) = 2 Then N = 1
    If Data(R, 2) = "WORK" Then
      Result(R, 1) = N
      N = N + 1
    End If
  Next
  Range("C2").Resize(UBound(Result)) = Result
End Sub

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (WorkDayEnumerator) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Last edited:
Upvote 0
Here is a formula to try:

=IF($B2="WORK",COUNTIFS($B$2:$B2,"WORK",$A$2:$A2,">="&($A2+1-MIN(DAY($A2),WEEKDAY($A2,2))),$A$2:$A2,"<="&$A2),"")
 
Upvote 0
Maybe...


A
B
C
1
Date​
Status​
My work day in week​
2
01/09/2017​
WORK​
1​
3
02/09/2017​
OFF​
4
03/09/2017​
WORK​
2​
5
04/09/2017​
OFF​
6
05/09/2017​
WORK​
1​
7
06/09/2017​
HOLIDAY​
8
07/09/2017​
WORK​
2​
9
08/09/2017​
WORK​
3​
10
09/09/2017​
OFF​
11
10/09/2017​
WORK​
4​
12
11/09/2017​
OFF​
13
12/09/2017​
OFF​
14
13/09/2017​
WORK​
1​
15
14/09/2017​
WORK​
2​
16
15/09/2017​
WORK​
3​
17
16/09/2017​
WORK​
4​
18
17/09/2017​
WORK​
5​
19
18/09/2017​
HOLIDAY​
20
19/09/2017​
OFF​
21
20/09/2017​
WORK​
1​
22
21/09/2017​
WORK​
2​
23
22/09/2017​
OFF​
24
23/09/2017​
WORK​
3​
25
24/09/2017​
HOLIDAY​
26
25/09/2017​
WORK​
1​
27
26/09/2017​
WORK​
2​
28
27/09/2017​
OFF​
29
28/09/2017​
OFF​
30
29/09/2017​
WORK​
3​
31
30/09/2017​
Work​
4​

Formula in C2 copied down
=IF(B2<>"WORK","",COUNTIFS(A$2:A2,">="&A2-IF(WEEKDAY(A2)=2,0,WEEKDAY(A2-2)),B$2:B2,"WORK"))

M.
 
Upvote 0
Or this simpler formula

C2 copied down
=IF(B2<>"WORK","",COUNTIFS(A$2:A2,">="&A2-CHOOSE(WEEKDAY(A2),6,0,1,2,3,4,5),B$2:B2,"WORK"))

M.
 
Upvote 0
Here is my updated formula as well (I just removed the redundant condition):

=IF($B2="WORK",COUNTIFS($B$2:$B2,"WORK",$A$2:$A2,">="&($A2+1-MIN(DAY($A2),WEEKDAY($A2,2)))),"")

In most cases, it returns values identical to those yielded by Rick's VBA solution and by Marcelo/Rick's formulas.

However, here is an example of where it differs: Sat 30-Sep-2017, Sun 1-Oct-2017, Mon 2-Oct-2017, all three are "WORK" days.
- My formula returns 1,1,1.
- Rick/Marcello's solutions return 1,2,1.

It's up to the OP to decide which result is the correct one.
 
Last edited:
Upvote 0
However, here is an example of where it differs: Sat 30-Sep-2017, Sun 1-Oct-2017, Mon 2-Oct-2017, all three are "WORK" days.
- My formula returns 1,1,1.
- Rick/Marcello's solutions return 1,2,1.
That situation should not be able to occur. In Message #3 , the OP said "...this formula will be used for many people and each month will be separate Sheet."
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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