Which returns 36 hours, based on a custom schedule where 8 hours are worked Mon-Fri, 4 hours are worked on Saturday, and Monday September 3 is a holiday. Holidays are supplied as the named range G6:G8. The work schedule is entered as a text string in column D and can be changed as desired. Note: This is an array formula that must be entered with Control + Shift + Enter. If you have a standard 8 hour workday, this formula is simpler. The trick to this formula is assembling an array of dates that you can feed into the WEEKDAY function. This is done with ROW with INDIRECT: ROW interprets the concatenated dates as row numbers and returns an array like this: Each number in the array represents a date. The WEEKDAY function then evaluates the array and returns an array of weekday values: These numbers correspond to the day of week of each date. They are provided to the MID function as the start number argument, along with the value in D6, “0888884” for text: Because we are giving MID an array of start numbers, it returns an array of results like this: These values correspond to the hours worked on each day from the start date to the end date. Note the values in this array are text, not numbers. To convert to actual numbers, we multiply by a second array created to manage holidays, as explained below. The math operation coerces the text to numeric values.
Holidays
To handle holidays, we use ISNA, MATCH, and the named range “holidays” like this: This expression uses MATCH to locate dates that are in the named range holidays using the same array of dates generated above with INDIRECT and ROW. MATCH returns a number when holidays are found and the #N/A error when not. The ISNA function “flips” the results so that TRUE represents holidays and FALSE represents non-holidays. ISNA returns an array or results like this: Finally, both arrays are multiplied by each other inside SUMPRODUCT. The math operation coerces TRUE and FALSE to 1 and zero, and the text values in the first array to numeric values (as explained above), so in the end we have: After multiplication, we have a single array inside SUMPRODUCT containing all working hours in the date range: SUMPRODUCT then sums all items in the array and returns a result of 36.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.