Forum Discussion
Calculate total working hours between date/time excluding weekends and break time
- Jul 15, 2024
I attached the wrong version, sorry.
The 2 hours in the first example is because the 1st of May is in the holiday list. If you remove that date from the holiday list, you get 3 hours.
See the attached version.
Here is a solution using a custom VBA function.
HansVogelaarHi thanks for responding, I changed the input but the result is still wrong, and it can't exclude lunch break.
- HansVogelaarJul 15, 2024MVP
I attached the wrong version, sorry.
The 2 hours in the first example is because the 1st of May is in the holiday list. If you remove that date from the holiday list, you get 3 hours.
See the attached version.
- VladLockhartJul 15, 2024Copper Contributor
HansVogelaar thanks dude it seems working just fine. But I can't copy it to my existing excel data. It always shows #NAME? can u help with that?
- HansVogelaarJul 15, 2024MVP
Open both my sample workbook and your workbook.
Press Alt+F11 to activate the Visual Basic Editor.
In the Project Explorer pane on the left hand side, expand TimeDifferenceWithBreak.xlsm, and Modules under it if necessary.
Drag Module1 to your workbook and drop it there.
Switch back to Excel.
Save your workbook as a macro-enabled workbook (*.xlsm)