If range of dates contains weekend

This tutorial shows how to test if a range of dates contain at least Saturday or Sunday and return a value if the test is True or False through the use of an Excel formula, with the IF, SUMPRODUCT and WEEKDAY functions

EXCEL FORMULA 1. If range of dates contains weekend

EXCEL

Hard coded formula
If range of dates contains weekend
Cell reference formula
If range of dates contains weekend
=IF(SUMPRODUCT(--(WEEKDAY(B5:B8,1)=1)+(WEEKDAY(B5:B8,1)=7))>0,"Contains Weekend","No Weekend")
=IF(SUMPRODUCT(--(WEEKDAY(B9:B12,1)=1)+(WEEKDAY(B9:B12,1)=7))>0,$C$5,$C$6)
GENERIC FORMULA

=IF(SUMPRODUCT(--(WEEKDAY(rng,1)=1)+(WEEKDAY(rng,1)=7))>0,value_if_true,value_if_false)

ARGUMENTS
rng: A range of dates that you want to test if any of them contain either Saturday or Sunday.
value_if_true: Value to be returned if the range of dates contain at least a Saturday or Sunday.
value_if_false: Value to be returned if the range of dates doesn't contain a Saturday or Sunday.

GENERIC FORMULA

=IF(SUMPRODUCT(--(WEEKDAY(rng,1)=1)+(WEEKDAY(rng,1)=7))>0,value_if_true,value_if_false)

ARGUMENTS
rng: A range of dates that you want to test if any of them contain either Saturday or Sunday.
value_if_true: Value to be returned if the range of dates contain at least a Saturday or Sunday.
value_if_false: Value to be returned if the range of dates doesn't contain a Saturday or Sunday.

EXPLANATION

This formula uses the IF, SUMPRODUCT and WEEKDAY functions to test if a range of dates has at least one day from a weekend (Saturday or Sunday) and return a value if the test is True or False.
Click on either the Hard Coded or Cell Reference button to view the formula that has the return values directly entered into the formula or referenced to specific cells.

In this example the formula identifies if at least one of the dates from a list of dates contains a weekend (Saturday or Sunday) through the use of the WEEKDAY and SUMPRODUCT functions. We have selected a return type of 1 for the WEEKDAY function, meaning if the WEEKDAY function returns a value of 1 or 7 it represents Sunday or Saturday, respectively. The SUMPRODUCT function is then used to sum the number of these occurrences. Then the IF function tests if there is at least one of these occurrences, meaning that there is at least one day from a weekend that is captured in the selected list. If the SUMPRODUCT function return a value of greater than zero the formula will return a text value of "Contains Weekend" otherwise it will return a text value of "No Weekend".

RELATED TOPICS

Related Topic Description Related Topic and Description
How to test if a date falls on a weekend and return a value if the test is True or False
How to test if a date is equal to another date and return a value if the test is True or False

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel IF function performs a test on specified conditions entered into the formula and returns a specified value if the result is TRUE or another specified value if the result is FALSE
The Excel WEEKDAY function returns a number between 1 and 7, representing the day of the week based on the return type that has been selected
The Excel SUMPRODUCT function multiplies corresponding ranges and returns the sum of these values