Need formula understanding

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Code:
=(NETWORKDAYS($AF2,$AG2,Lookup_table!$J$2:$J$10)-1)*("19:00"-"7:00")+IF(NETWORKDAYS($AG2,$AG2,Lookup_table!$J$2:$J$10),MEDIAN(MOD($AG2,1),"19:00","7:00"),"19:00")-MEDIAN(NETWORKDAYS($AF2,$AF2,Lookup_table!$J$2:$J$10)*MOD($AF2,1),"19:00","7:00")

can anyone pls explain and understand me how this formula working..
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi VBABeginner,
chopping your formula into bits. I'm assuming AF2 and AG2 have dates in them.

Code:
=(NETWORKDAYS($AF2,$AG2,Lookup_table!$J$2:$J$10)-1)*("19:00"-"7:00")
+IF(NETWORKDAYS($AG2,$AG2,Lookup_table!$J$2:$J$10),MEDIAN(MOD($AG2,1),"19:00","7:00"),"19:00")
-MEDIAN(NETWORKDAYS($AF2,$AF2,Lookup_table!$J$2:$J$10)*MOD($AF2,1),"19:00","7:00")

Line 1: This is basically calculating a number of days worked. The first block (NETWORKDAYS) is multiplied by 0,5 (12 hours from 7 to 19 divided by 24 hours in a day). It calculates the net workdays in the period between two days (AF2 and AG2) given the holidays in Lookup_table!J2:J10.
For NETWORKDAYS: it includes the days put into it: so if AG2 is equal to AF2, it will return 1. One exception: if AG2 is in the list of holidays, then it will return a 0. The MOD makes sure you only take the hour part of your date/time value. The MEDIAN makes sures it's between 7h and 19h.
So line 2 determines the hour of AG2, limited by 19h and 7h, line 3 does the same for AF2. That should give the number of hours between AG2 and AF2, given a workday from 7 to 19 and the holidays int he Lookup_table.

Hope that helps,
Koen
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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