Formula/VBA calculation with Time help!

aspinray

New Member
Joined
Jan 14, 2016
Messages
16
Hi,

I have no idea what I am doing and every time I post in here you all help me out so much and I am really grateful. So here I am again!

So, I have put tables below to try and help explain. I have two reports, one that pulls dates for holidays, the date, name of the person, and if it is a full day or not. I then have another report that shows shifts for that person day to day, with start and end times and lunch times.

What is need is for the holiday report to show paid hours, minus lunch breaks, at the end of each row. The only way i think think to do this is by looking at the second report i have this is the shift report, mentioned above. So, match the persons name and date on both reports, look at start and end time, 08.00-16.00, then work out paid hours. Problem I have is everyone has different lunches and therefore the report will say 36 mins @ 4hrs 15 mins or 30 mins @ 3 hrs. As there are 1000s of requests i wondered if there was anything I could do to make this process automatic. So, the macro or formula once its matched name and date, figures the shift hours out then looks at the lunch and takes this off the total hours - so 08.00 - 16.00 is 08.00 hours minus 36 mins lunch is 07.24.

Finally, i need to only take the lunch into account if the shift is over 6 hours, otherwise the lunch doesn't get taken into account.

I am not sure how to attach excel documents, or if you can.. but below is what the reports look like.

Please let me know if you need any more information, thanks in advance!

[TABLE="width: 1032, align: left"]
<tbody>[TR]
[TD][/TD]
[TD="colspan: 3"]Holiday Report[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Date Period:[/TD]
[TD="colspan: 2"]05/06/17 - 31/12/17[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]I need this to populate automatically[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]a[/TD]
[TD]b[/TD]
[TD]c[/TD]
[TD]d[/TD]
[TD]e[/TD]
[TD]f[/TD]
[TD]g[/TD]
[TD]h[/TD]
[TD]i[/TD]
[TD]j[/TD]
[TD]k[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Site[/TD]
[TD]Time zone[/TD]
[TD]Team[/TD]
[TD]Agent[/TD]
[TD]Date[/TD]
[TD]Type[/TD]
[TD]Description[/TD]
[TD]Start Time[/TD]
[TD]End Time[/TD]
[TD]Status[/TD]
[TD]Paid Hours[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]05/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]06/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]07/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]08/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]09/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]14/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]15/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]First Choice Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]NE- Enhance[/TD]
[TD]GMT[/TD]
[TD]AB - Joe Smith[/TD]
[TD]Name Surname[/TD]
[TD]16/06/2017[/TD]
[TD]Full Day Exception[/TD]
[TD]Holiday Full Day[/TD]
[TD]Full Day[/TD]
[TD]Full Day[/TD]
[TD]Granted[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Date Period:
abcdefghij
1SiteTime zoneTeamAgentDateTypeDescriptionStart TimeEnd TimeStatus
2NE- EnhanceGMTAB - Joe SmithName Surname05/06/2017Rotating Pattern (Granted Fixed Shift)4-10hrs 36mins @ 4hrs 15 mins09:0017:00Granted
3NE- EnhanceGMTAB - Joe SmithName Surname06/06/2017Rotating Pattern (Granted Fixed Shift)4-10hrs 36mins @ 4hrs 15 mins09:0017:00Granted
4NE- EnhanceGMTAB - Joe SmithName Surname07/06/2017Rotating Pattern (Granted Fixed Shift)4-10hrs 36mins @ 4hrs 15 mins09:0017:00Granted
5NE- EnhanceGMTAB - Joe SmithName Surname08/06/2017Rotating Pattern (Granted Fixed Shift)4-10hrs 36mins @ 4hrs10:0014:00Granted
6NE- EnhanceGMTAB - Joe SmithName Surname09/06/2017Rotating Pattern (Granted Fixed Shift)4-10hrs 36mins @ 3hrs 24 mins12:0020:00Granted
7NE- EnhanceGMTAB - Joe SmithName Surname10/06/2017Rotating Pattern (Day Off)Day OffFull DayFull DayGranted
8NE- EnhanceGMTAB - Joe SmithName Surname11/06/2017Rotating Pattern (Day Off)Day OffFull DayFull DayGranted

<tbody>
[TD="colspan: 3"][/TD]

[TD="colspan: 3"]Shift Report[/TD]

[TD="colspan: 2"]05/06/17 – 31/12/17[/TD]

</tbody>
 

Excel Facts

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

Not VBA but with formula. Take a look at this:

Excel 2016 (Windows) 64 bit
ABCDEFGHIJK
1SiteTime zoneTeamAgentDateTypeDescriptionStart TimeEnd TimeStatusPaid Hours
2NE- EnhanceGMTAB - Joe SmithName Surname5-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted07:24
3NE- EnhanceGMTAB - Joe SmithName Surname6-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted07:24
4NE- EnhanceGMTAB - Joe SmithName Surname7-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted07:24
5NE- EnhanceGMTAB - Joe SmithName Surname8-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted00:00
6NE- EnhanceGMTAB - Joe SmithName Surname9-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted07:24
7NE- EnhanceGMTAB - Joe SmithName Surname14-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted00:00
8NE- EnhanceGMTAB - Joe SmithName Surname15-6-2017Full Day ExceptionFirst Choice Holiday Full DayFull DayFull DayGranted00:00
9NE- EnhanceGMTAB - Joe SmithName Surname16-6-2017Full Day ExceptionHoliday Full DayFull DayFull DayGranted00:00
holiday report
Cell Formulas
RangeFormula
K2{=IFERROR(IF(INDEX('Shift report'!$G$2:$G$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0))="Full Day",0,((INDEX('Shift report'!$I$2:$I$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)))-INDEX('Shift report'!$H$2:$H$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:D8&'Shift report'!$E$2:$E$8,0)))-IF(((INDEX('Shift report'!$I$2:$I$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)))-INDEX('Shift report'!$H$2:$H$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)))>(LEFT(INDEX('Shift report'!$G$2:$G$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)),1)/24),VALUE(MID(INDEX('Shift report'!$G$2:$G$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)),SEARCH("Hrs ",INDEX('Shift report'!$G$2:$G$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)),1)+4,2)),VALUE(MID(INDEX('Shift report'!$G$2:$G$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)),SEARCH("@*Hrs ",INDEX('Shift report'!$G$2:$G$8,MATCH(C2&D2&E2,'Shift report'!$C$2:$C$8&'Shift report'!$D$2:$D$8&'Shift report'!$E$2:$E$8,0)),1)+7,2)))/(60*24)),0)}
Press CTRL+SHIFT+ENTER to enter array formulas.


Beware: Cell K5 returns 0 as there's no minutes mentioned in the Shift Report cell G5 for up to 4 hrs
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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