Hi @
malbarki !
This has gone a bit tricky, the problem is not with using named range. The problem is with comparison of two array with different dimensions using comparitive operators.
Just see the attached file (
Sheet 1)
In column A I had entered Start Date/Time. In Column B I had entered End Date/Time.
In column C I had calculated total time in minutes excluding weekends (Friday & Saturday), any non-official time & holidays using below formula.
=(((SUMPRODUCT(IF((WEEKDAY(ROW(INDIRECT(INT(A2)&":"&INT(B2))),1)=6)+(WEEKDAY(ROW(INDIRECT(INT(A2)&":"&INT(B2))),1)=7),0,1))-SUMPRODUCT(IF(IFERROR(MATCH(ROW(INDIRECT(INT(A2)&":"&INT(B2))),Holiday,0),0),1,0)))*9)-(IF(INT(B2)=IFERROR(INDEX(Holiday,MATCH(INT(B2),Holiday,0)),0),0,((WEEKDAY(B2,1)<6)*MAX(0,MIN(9,17-MOD(B2,1)*24)))))-(IF(INT(A2)=IFERROR(INDEX(Holiday,MATCH(INT(A2),Holiday,0)),0),0,((WEEKDAY(A2,1)<6)*MAX(0,MIN(9,MOD(A2,1)*24-8))))))*60
(Note: This is an array formula so Ctrl+Shift+Enter is must after entering it. Enter in C2 with CSE and copy down)
My Holiday list is in column E. I had used dynamic named range HOLIDAY. I had use below formula to create it.
=Sheet1!$E$2:INDEX(Sheet1!$E$2:$E$10,COUNTA(Sheet1!$E$2:$E$10))
Just check all the possible cases. I had checked some of them. Advise if any issue.
Regards!