Count hours on specific days and time, return value in decimal hours

Want2BExcel

Board Regular
Joined
Nov 24, 2021
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
I want to count the hours from Saturday 14:00 to Mondag 06:00 and return value in decimal hours. But should ignore ALL if [Tidsart1] column E's value is "volunteer" (this last part I haven't included in any formula yet.
I'm trying to simplify the formula in the TEST (AK) column or combine thoose I've got (when errors is corrected). Right now it's a bunch of different formulas. Some are working, some has errors (Marked with red in the table)

There's 3x2 time colums. C+D (start1-stop1), F+G (start2-stop2), I+J (start3-stop3). There isn't always has data in all 3. If C+D don't, then the rest will not either, in that case, the result should alwasy be 0

[Tuesdag to Friday]=AK29:AK32,AK22:AK25,AK15:AK18,AK8:AK11,AK2:AK4 - This formula is working

[Monday]=AK7,AK28,AK21,AK14 - This formula seems to work somewhat ok if the result is positive, but I want it to return a value of 0 if the result is negative

[Saturday]=AK5,AK26,AK19,AK12 - This formula's result confuse me. In AK5 it looks to be working fine, only counting the hours from 14:00-15:00, but in AK12 it is not working, since it's counting all hours from F+G (12:45-15:00), I+J (19:00-00:00), but correctly ignores C+D (00:00-01:00). So it looks like I have an issue when there's data in other time columns than C+D

[Sunday]=AK6,AK27,AK20,AK13 - This formula is working, but seems a bit comprehensive when all hours should be counted


Arb.tid & Friheder TEST.xlsx
ABCDEFGHIJKAK
1UgedagDatoStart1Slut1Tidsart1Start2Slut2Tidsart2Start3Slut3Tidsart3TEST
2Onsdag01-12-2107:3015:30FTG0
3Torsdag02-12-2107:3014:30FTG0
4Fredag03-12-2107:3013:30FTG0
5Lørdag04-12-2112:4515:00T1
6Søndag05-12-2100:0001:00T12:4515:00T19:0000:00T8,25
7Mandag06-12-2106:4508:30R-0,75
8Tirsdag07-12-2100:0001:00T14:4500:00T0
9Onsdag08-12-2100:0001:00T14:4500:00T0
10Torsdag09-12-2100:0001:00T12:4500:00T0
11Fredag10-12-2100:0001:00T14:4500:00T0
12Lørdag11-12-2100:0001:00T12:4515:00T19:0000:00T7,25
13Søndag12-12-2117:4520:15R2,5
14Mandag13-12-2100:0008:30R6
15Tirsdag14-12-2107:3015:30FTG0
16Onsdag15-12-2107:3015:30FTG0
17Torsdag16-12-2107:3014:30FTG0
18Fredag17-12-2107:3013:30§170
19Lørdag18-12-210
20Søndag19-12-210
21Mandag20-12-2108:0017:00T-2
22Tirsdag21-12-2107:3015:30T0
23Onsdag22-12-2107:3015:30T0
24Torsdag23-12-2107:3014:30T0
25Fredag24-12-2107:3013:30T0
26Lørdag25-12-2107:3015:30volunteer1,5
27Søndag26-12-2107:3015:30volunteer8
28Mandag27-12-2105:3015:30volunteer0,5
29Tirsdag28-12-2107:3015:30T0
30Onsdag29-12-2107:3015:30T0
31Torsdag30-12-2107:3014:30T0
32Fredag31-12-2107:3013:30T0
Dec.21
Cell Formulas
RangeFormula
AK29:AK32,AK22:AK25,AK15:AK18,AK8:AK11,AK2:AK4AK2=(IF(OR([@Ugedag]="Tirsdag",[@Ugedag]="Onsdag",[@Ugedag]="Torsdag",[@Ugedag]="Fredag",0),0))
AK5,AK26,AK19,AK12AK5=24*((IF(OR([@Ugedag]="Lørdag",[@Start1]<TIME(14,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(14,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(14,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(14,0,0),0))))+(IF(OR([@Start2]>TIME(14,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(14,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(14,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(14,0,0),0))))+(IF(OR([@Start3]>TIME(14,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(14,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(14,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(14,0,0),0)))))
AK6,AK27,AK20,AK13AK6=24*((IF(OR([@Ugedag]="Søndag",[@Start1]<TIME(0,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(0,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(0,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(0,0,0),0))))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(0,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(0,0,0),0))))+(IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(0,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(0,0,0),0)))))
AK7,AK28,AK21,AK14AK7=24*((IF(OR([@Ugedag]="Mandag",[@Start1]>TIME(0,0,0),[@Start1]="",[@Slut1]=""),MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(6,0,0))-MAX([@Start1],0,0)),0))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],6,0),0))+IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],6,0),0))))
 
example file
correct, you call that UDF in the worksheet with for example
Excel Formula:
=w2be(Tabel1[@[Ugedag]:[Tidsart3]])
I got it to work with this
Excel Formula:
=w2be([@Ugedag]:[@Tidsart3])

But not all results are correct (as they are on your examble). I have changed some times to test the functionallity. And added a column just to show you what all the correct results should be.

here is mine...
Arb.tid & Friheder TEST.xlsx
ABCDEFGHIJKAKALAM
1UgedagDatoStart1Slut1Tidsart1Start2Slut2Tidsart2Start3Slut3Tidsart3TESTUDF
2Onsdag01-12-2107:3015:30FTG000
3Torsdag02-12-2107:3014:30FTG000
4Fredag03-12-2107:3013:30FTG000
5Lørdag04-12-2112:4515:00T111
6Søndag05-12-2100:0001:00T12:4515:00T19:0000:00T8,253,258,25
7Mandag06-12-2106:4508:30R-0,7500
8Tirsdag07-12-2100:0001:00T14:4500:00T000
9Onsdag08-12-2100:0001:00T14:4500:00T000
10Torsdag09-12-2100:0001:00T12:4500:00T000
11Fredag10-12-2100:0001:00T14:4500:00T000
12Lørdag11-12-2100:0001:00T12:4515:00T19:0000:00T7,2515
13Søndag12-12-2117:4520:15R2,52,52,5
14Mandag13-12-2100:0003:30T04:3005:00T05:3008:00T3,54,54,5
15Tirsdag14-12-2107:3015:30FTG000
16Onsdag15-12-2107:3015:30FTG000
17Torsdag16-12-2107:3014:30FTG000
18Fredag17-12-2107:3013:30§17000
19Lørdag18-12-21000
20Søndag19-12-21000
21Mandag20-12-2108:0017:00T-200
22Tirsdag21-12-2107:3015:30T000
23Onsdag22-12-2107:3015:30T000
24Torsdag23-12-2107:3014:30T000
25Fredag24-12-2107:3013:30T000
26Lørdag25-12-2107:3015:30volunteer000
27Søndag26-12-2107:3015:30volunteer000
28Mandag27-12-2105:3015:30volunteer000
29Tirsdag28-12-2107:3015:30T000
30Onsdag29-12-2107:3015:30T000
31Torsdag30-12-2107:3014:30T000
32Fredag31-12-2107:3013:30T000
Dec.21
Cell Formulas
RangeFormula
AK29:AK32,AK22:AK25,AK15:AK18,AK8:AK11,AK2:AK4AK2=(IF(OR([@Ugedag]="Tirsdag",[@Ugedag]="Onsdag",[@Ugedag]="Torsdag",[@Ugedag]="Fredag",0),0))
AL2:AL32AL2=w2be([@Ugedag]:[@Tidsart3])
AK5,AK26,AK19,AK12AK5=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Lørdag",[@Start1]<TIME(14,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(14,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(14,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(14,0,0),0))))+(IF(OR([@Start2]>TIME(14,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(14,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(14,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(14,0,0),0))))+(IF(OR([@Start3]>TIME(14,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(14,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(14,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(14,0,0),0)))))))
AK6,AK27,AK20,AK13AK6=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Søndag",[@Start1]<TIME(0,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(0,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(0,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(0,0,0),0))))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(0,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(0,0,0),0))))+(IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(0,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(0,0,0),0)))))))
AK7,AK28,AK21,AK14AK7=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Mandag",[@Start1]>TIME(0,0,0),[@Start1]="",[@Slut1]=""),MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(6,0,0))-MAX([@Start1],0,0)),0))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],6,0),0))+IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],6,0),0))))))
 
Last edited:
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I got it to work with this
Excel Formula:
=w2be([@Ugedag]:[@Tidsart3])

But not all results are correct (as they are on your examble). I have changed some times to test the functionallity. And added a column just to show you what all the correct results should be.

here is mine...
Arb.tid & Friheder TEST.xlsx
ABCDEFGHIJKAKALAM
1UgedagDatoStart1Slut1Tidsart1Start2Slut2Tidsart2Start3Slut3Tidsart3TESTUDF
2Onsdag01-12-2107:3015:30FTG000
3Torsdag02-12-2107:3014:30FTG000
4Fredag03-12-2107:3013:30FTG000
5Lørdag04-12-2112:4515:00T111
6Søndag05-12-2100:0001:00T12:4515:00T19:0000:00T8,253,258,25
7Mandag06-12-2106:4508:30R-0,7500
8Tirsdag07-12-2100:0001:00T14:4500:00T000
9Onsdag08-12-2100:0001:00T14:4500:00T000
10Torsdag09-12-2100:0001:00T12:4500:00T000
11Fredag10-12-2100:0001:00T14:4500:00T000
12Lørdag11-12-2100:0001:00T12:4515:00T19:0000:00T7,2515
13Søndag12-12-2117:4520:15R2,52,52,5
14Mandag13-12-2100:0003:30T04:3005:00T05:3008:00T3,54,54,5
15Tirsdag14-12-2107:3015:30FTG000
16Onsdag15-12-2107:3015:30FTG000
17Torsdag16-12-2107:3014:30FTG000
18Fredag17-12-2107:3013:30§17000
19Lørdag18-12-21000
20Søndag19-12-21000
21Mandag20-12-2108:0017:00T-200
22Tirsdag21-12-2107:3015:30T000
23Onsdag22-12-2107:3015:30T000
24Torsdag23-12-2107:3014:30T000
25Fredag24-12-2107:3013:30T000
26Lørdag25-12-2107:3015:30volunteer000
27Søndag26-12-2107:3015:30volunteer000
28Mandag27-12-2105:3015:30volunteer000
29Tirsdag28-12-2107:3015:30T000
30Onsdag29-12-2107:3015:30T000
31Torsdag30-12-2107:3014:30T000
32Fredag31-12-2107:3013:30T000
Dec.21
Cell Formulas
RangeFormula
AK29:AK32,AK22:AK25,AK15:AK18,AK8:AK11,AK2:AK4AK2=(IF(OR([@Ugedag]="Tirsdag",[@Ugedag]="Onsdag",[@Ugedag]="Torsdag",[@Ugedag]="Fredag",0),0))
AL2:AL32AL2=w2be([@Ugedag]:[@Tidsart3])
AK5,AK26,AK19,AK12AK5=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Lørdag",[@Start1]<TIME(14,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(14,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(14,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(14,0,0),0))))+(IF(OR([@Start2]>TIME(14,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(14,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(14,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(14,0,0),0))))+(IF(OR([@Start3]>TIME(14,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(14,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(14,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(14,0,0),0)))))))
AK6,AK27,AK20,AK13AK6=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Søndag",[@Start1]<TIME(0,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(0,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(0,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(0,0,0),0))))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(0,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(0,0,0),0))))+(IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(0,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(0,0,0),0)))))))
AK7,AK28,AK21,AK14AK7=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Mandag",[@Start1]>TIME(0,0,0),[@Start1]="",[@Slut1]=""),MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(6,0,0))-MAX([@Start1],0,0)),0))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],6,0),0))+IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],6,0),0))))))
AM12 should be 6, sorry :rolleyes:
but there only 2 errors...which I think it has something to do with my 00:00 in Slut3 (TimeEnding3)
 
Upvote 0
I got it to work with this
Excel Formula:
=w2be([@Ugedag]:[@Tidsart3])

But not all results are correct (as they are on your examble). I have changed some times to test the functionallity. And added a column just to show you what all the correct results should be.

here is mine...
Arb.tid & Friheder TEST.xlsx
ABCDEFGHIJKAKALAM
1UgedagDatoStart1Slut1Tidsart1Start2Slut2Tidsart2Start3Slut3Tidsart3TESTUDF
2Onsdag01-12-2107:3015:30FTG000
3Torsdag02-12-2107:3014:30FTG000
4Fredag03-12-2107:3013:30FTG000
5Lørdag04-12-2112:4515:00T111
6Søndag05-12-2100:0001:00T12:4515:00T19:0000:00T8,253,258,25
7Mandag06-12-2106:4508:30R-0,7500
8Tirsdag07-12-2100:0001:00T14:4500:00T000
9Onsdag08-12-2100:0001:00T14:4500:00T000
10Torsdag09-12-2100:0001:00T12:4500:00T000
11Fredag10-12-2100:0001:00T14:4500:00T000
12Lørdag11-12-2100:0001:00T12:4515:00T19:0000:00T7,2515
13Søndag12-12-2117:4520:15R2,52,52,5
14Mandag13-12-2100:0003:30T04:3005:00T05:3008:00T3,54,54,5
15Tirsdag14-12-2107:3015:30FTG000
16Onsdag15-12-2107:3015:30FTG000
17Torsdag16-12-2107:3014:30FTG000
18Fredag17-12-2107:3013:30§17000
19Lørdag18-12-21000
20Søndag19-12-21000
21Mandag20-12-2108:0017:00T-200
22Tirsdag21-12-2107:3015:30T000
23Onsdag22-12-2107:3015:30T000
24Torsdag23-12-2107:3014:30T000
25Fredag24-12-2107:3013:30T000
26Lørdag25-12-2107:3015:30volunteer000
27Søndag26-12-2107:3015:30volunteer000
28Mandag27-12-2105:3015:30volunteer000
29Tirsdag28-12-2107:3015:30T000
30Onsdag29-12-2107:3015:30T000
31Torsdag30-12-2107:3014:30T000
32Fredag31-12-2107:3013:30T000
Dec.21
Cell Formulas
RangeFormula
AK29:AK32,AK22:AK25,AK15:AK18,AK8:AK11,AK2:AK4AK2=(IF(OR([@Ugedag]="Tirsdag",[@Ugedag]="Onsdag",[@Ugedag]="Torsdag",[@Ugedag]="Fredag",0),0))
AL2:AL32AL2=w2be([@Ugedag]:[@Tidsart3])
AK5,AK26,AK19,AK12AK5=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Lørdag",[@Start1]<TIME(14,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(14,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(14,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(14,0,0),0))))+(IF(OR([@Start2]>TIME(14,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(14,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(14,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(14,0,0),0))))+(IF(OR([@Start3]>TIME(14,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(14,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(14,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(14,0,0),0)))))))
AK6,AK27,AK20,AK13AK6=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Søndag",[@Start1]<TIME(0,0,0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(0,0,0))-MAX([@Start1],0,0))))+(IF(OR(AND([@Slut1]<TIME(0,0,0),[@Slut1]<>0),[@Start1]="",[@Slut1]=""),0,MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),1)-MAX([@Start1],TIME(0,0,0),0))))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],0,0))))+(IF(OR(AND([@Slut2]<TIME(0,0,0),[@Slut2]<>0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),1)-MAX([@Start2],TIME(0,0,0),0))))+(IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],0,0))))+(IF(OR(AND([@Slut3]<TIME(0,0,0),[@Slut3]<>0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),1)-MAX([@Start3],TIME(0,0,0),0)))))))
AK7,AK28,AK21,AK14AK7=24*((IF([@Tidsart1]="volunteer",0,(IF(OR([@Ugedag]="Mandag",[@Start1]>TIME(0,0,0),[@Start1]="",[@Slut1]=""),MAX(MIN((IF([@Slut1]<[@Start1],1,[@Slut1])),TIME(6,0,0))-MAX([@Start1],0,0)),0))+(IF(OR([@Start2]>TIME(0,0,0),[@Start2]="",[@Slut2]=""),0,MAX(MIN((IF([@Slut2]<[@Start2],1,[@Slut2])),TIME(0,0,0))-MAX([@Start2],6,0),0))+IF(OR([@Start3]>TIME(0,0,0),[@Start3]="",[@Slut3]=""),0,MAX(MIN((IF([@Slut3]<[@Start3],1,[@Slut3])),TIME(0,0,0))-MAX([@Start3],6,0),0))))))
I can't understand, that the results should be correct, for the test you have made in example #11. How can Saturday 11-12-2021 be 5 hours ? It should by a normally count, be 8,25. Or?
 
Upvote 0
I can't understand, that the results should be correct, for the test you have made in example #11. How can Saturday 11-12-2021 be 5 hours ? It should by a normally count, be 8,25. Or?
Hi ebea,
You probably didn't saw this ? and it should be 6 as I correct edited in #12. Because it's a Saturday, the count should only take the hours FROM 14:00 to 00:00
I also wrote it in bold, in my first line in question #1
- formula on Saturdays [that is Lørdag] count the hours from 14:00 to 00:00
- formula on Sundays [that is Søndag] count the hours from 00:00 to 00:00
- formula on Mondays [that is Mandag] count the hours from 00:00 to 06:00
and when they all worked, I would try and combine them into 1 LONG formula, so all would have the same, but results would be diffenrent depending on the data
 
Last edited:
Upvote 0
General conclusion, my UDF now makes no errors if you use 23:59:59 or just 1 (to have 24:00:00, perhaps better use numberformat [hh]:mm, like i already did in #4 and #7) ?

With an excel 2016, the newest formulas (LET, ...) aren't available, so that 'll be a long formula.
I stop here, because such long formulas, i'm not a big fan.
But as a way to simplify the formula, add 2 aux. columns in which you calculate for every sat-mon the start hour for sat 14:00 and mon 6:00. That 'll shorten your formula with the 50%
 
Last edited:
Upvote 0
you start writing and the formula is almost there
Cell Formulas
RangeFormula
AL2:AL9AL2=w2be(Tabel1[@[Ugedag]:[Tidsart3]])
AM2:AM9AM2=IF(WEEKDAY([@Dato],16)<=3,[@Dato]-WEEKDAY([@Dato],16)+1+TIME(14,0,0),"-")
AN2:AN9AN2=IF(WEEKDAY([@Dato],16)<=3,[@Dato]-WEEKDAY([@Dato],16)+3+TIME(6,0,0),"-")
AO2:AO9AO2=IF(ISNUMBER([@Sat]),24*( IF(COUNT(Tabel1[@[Start1]:[Slut1]])=2,MAX(0,MIN([@Slut1]+[@Dato],[@Mon])-MAX([@Sat],[@Dato]+[@Start1])),0)+ IF(COUNT(Tabel1[@[Start2]:[Slut2]])=2,MAX(0,MIN([@Slut2]+[@Dato],[@Mon])-MAX([@Sat],[@Dato]+[@Start2])),0)+ IF(COUNT(Tabel1[@[Start3]:[Slut3]])=2,MAX(0,MIN([@Slut3]+[@Dato],[@Mon])-MAX([@Sat],[@Dato]+[@Start3])),0)), "-")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AL1:AL32Expression=AL1=0textNO

w2be
with a screenshot of the dutch formula, you see better how it works
 

Attachments

  • Schermafbeelding 2022-02-13 152828.png
    Schermafbeelding 2022-02-13 152828.png
    16.8 KB · Views: 10
Last edited:
Upvote 0
General conclusion, my UDF now makes no errors if you use 23:59:59 or just 1 (to have 24:00:00, perhaps better use numberformat [hh]:mm, like i already did in #4 and #7) ?

With an excel 2016, the newest formulas (LET, ...) aren't available, so that 'll be a long formula.
I stop here, because such long formulas, i'm not a big fan.
But as a way to simplify the formula, add 2 aux. columns in which you calculate for every sat-mon the start hour for sat 14:00 and mon 6:00. That 'll shorten your formula with the 50%
Sometimes I can be so focused on a solution, that I can't see the obvious ??
I was so close ?? but as you pointed out, the formulas was incredible long and that was even before I was at a point where I could combine them.
I got the Mondays, Sundays and Tuesday-Friday to work, each by it self, but the Saturdays gave me a headache ?
I could make Saturday work when I broke it up, timeblock by timeblock, but when I tried putting the formulas together, I had the weirdest results, because the formuls worked differently when put together ? I could see where the problem was, but I didn't understand why since they worked fine, each on its own ? probably missed a "few" )))))((((<> somewhere.
So I did what you suggested and made some aux. colums and SUM them afterwards....so easy! I'm embarrassed that I didn't do that days ago. Well, lessons learned ?
I saved your UDF macro, for personal use, since it work fine now ?? it's also the one I mark as the solution, since it's the best way to solve a problem like this.
BSALV, Thank you for your patience and time ?
I learned a great deal ???
 
Upvote 0
as you can see in the screenshot, in the formula bar, you can add several "ALT+Enter" after a part of your formula, so the different parts stand all on a different line and are easy to compare/modify.
Therefore click on that arrow-down symbol at the right of the formulabar.
Those "ALT+Enter" have only visual effect, but doesn't change the calculations.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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