Explanation
At the core, this formula uses the WEEKDAY function to test a number of dates to see if they land on a given day of week (dow) and the SUMPRODUCT function to tally up the total.
When given a date, WEEKDAY simply returns a number between 1 and 7 that corresponds to a particular day of the week. With default settings, 1 = Sunday and 7 = Saturday. So, 2 = Monday, 6 = Friday, and so on.
The trick to this formula is understanding that dates in Excel are just serial numbers that begin on Jan 1, 1900. For example, January 1, 2016 is the serial number 42370, and January 8 is 42377. Dates in Excel only look like dates when a date number format is applied.
So, the question becomes - how can you construct an array of dates that you can feed into the WEEKDAY function to find out corresponding days of week?
The answer is to use ROW with INDIRECT functions like so:
ROW(INDIRECT(date1&":"&date2))
INDIRECT allows the concatenated dates “42370:42377” to be interpreted as row numbers. Then the ROW function returns an array like this:
{42370;42371;42372;42373;42374;42375;42376;42377}
The WEEKDAY function evaluates these numbers as dates and returns this array:
{6;7;1;2;3;4;5;6}
which is tested against the given day of week (6 in this case, from D6). Once the results of the test are converted to 1s and 0s with the double hyphen, this array is processed by SUMPRODUCT:
{1;0;0;0;0;0;0;1}
Which returns 2.
With SEQUENCE
With the new SEQUENCE function , this formula can simplified somewhat like this:
=SUMPRODUCT(--(WEEKDAY(SEQUENCE(end-start+1,1,start,1))=dow))
In this version, we use SEQUENCE to generate the array of dates directly, with no need for INDIRECT or ROW.
Dynamic Array Formulas are available in Office 365 only.
Explanation
This formula uses two expressions in a single array inside the SUMPRODUCT function.
The first expression tests every holiday date to see if it’s greater than or equal to the start date in F5:
(B4:B12>=F5)
This returns an array of TRUE/FALSE values like this:
{FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE}
The second expression tests every holiday date to see if it’s less than or equal to the end date in F6:
(B4:B12<=F6)
which returns an array of TRUE/FALSE values like this:
{TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;FALSE}
The multiplication of these two arrays automatically coerces the TRUE/FALSE values to ones and zeros, resulting in arrays that look like this:
=SUMPRODUCT(({0;0;0;0;1;1;1;1;1})*({1;1;1;1;1;1;1;1;0}))
After multiplication, we have just one array like this:
=SUMPRODUCT({0;0;0;0;1;1;1;1;0})
Finally, SUMPRODUCT sums the items in the array and returns 4.
Holidays on weekdays only
To count holidays that occur on weekdays only (Mon-Fri), you can extend the formula like this:
=SUMPRODUCT((rng>=F5)*(rng<=F6)*(WEEKDAY(rng,2)<6))
where rng is a range containing holiday dates.