Page 281 - Excel 2007 Bible
P. 281
18_044039 ch13.qxp 11/21/06 11:05 AM Page 238
Part II
Working with Formulas and Functions
If cell A1 contains June 1, 2007 (a Friday), and cell A2 contains 2 (for Monday), the formula returns June 4,
2007. This is the first Monday after June 1, 2004.
Determining the nth occurrence of a day
of the week in a month
You may need a formula to determine the date for a particular occurrence of a week day. For example, sup-
pose that your company payday falls on the second Friday of each month, and you need to determine the
paydays for each month of the year. The following formula will make this type of calculation:
=DATE(A1,A2,1)+A3-WEEKDAY(DATE(A1,A2,1))+
(A4-(A3>=WEEKDAY(DATE(A1,A2,1))))*7
The formula in this section assumes that:
n Cell A1 contains a year.
n Cell A2 contains a month.
n Cell A3 contains a day number (1 for Sunday, 2 for Monday, and so on).
n Cell A4 contains the occurrence number (for example, 2 to select the second occurrence of the
weekday specified in cell A3).
If you use this formula to determine the date of the second Friday in November 2007, it returns November
11, 2007.
NOTE If the value in cell A4 exceeds the number of the specified day in the month, the formula
NOTE
returns a date from a subsequent month. For example, if you attempt to determine the date of
the fifth Friday in November 2007 (there is no such date), the formula returns the first Friday in December.
Calculating dates of holidays
Determining the date for a particular holiday can be tricky. Some, such as New Year’s Day and U.S.
Independence Day are no-brainers because they always occur on the same date. For these kinds of holidays,
you can simply use the DATE function. To enter New Year’s Day (which always falls on January 1) for a spe-
cific year in cell A1, you can enter this function:
=DATE(A1,1,1)
Other holidays are defined in terms of a particular occurrence of a particular week day in a particular
month. For example, Labor Day falls on the first Monday in September.
Figure 13.5 shows a workbook with formulas that calculate the date for ten U.S. holidays. The formulas,
which reference the year in cell A1, are listed in the sections that follow.
238