18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Part II<br />

Working with Formulas and Functions<br />

If cell A1 contains June 1, 2007 (a Friday), and cell A2 contains 2 (for Monday), the formula returns June 4,<br />

2007. This is the first Monday after June 1, 2004.<br />

Determining the nth occurrence of a day<br />

of the week in a month<br />

You may need a formula to determine the date for a particular occurrence of a week day. For example, suppose<br />

that your company payday falls on the second Friday of each month, and you need to determine the<br />

paydays for each month of the year. The following formula will make this type of calculation:<br />

=DATE(A1,A2,1)+A3-WEEKDAY(DATE(A1,A2,1))+<br />

(A4-(A3>=WEEKDAY(DATE(A1,A2,1))))*7<br />

The formula in this section assumes that:<br />

n<br />

n<br />

n<br />

n<br />

Cell A1 contains a year.<br />

Cell A2 contains a month.<br />

Cell A3 contains a day number (1 for Sunday, 2 for Monday, and so on).<br />

Cell A4 contains the occurrence number (for example, 2 to select the second occurrence of the<br />

weekday specified in cell A3).<br />

If you use this formula to determine the date of the second Friday in November 2007, it returns November<br />

11, 2007.<br />

If the value in cell A4 exceeds the number of the specified day in the month, the formula<br />

returns a date from a subsequent month. For example, if you attempt to determine the date of<br />

the fifth Friday in November 2007 (there is no such date), the formula returns the first Friday in December.<br />

NOTE<br />

Calculating dates of holidays<br />

Determining the date for a particular holiday can be tricky. Some, such as New Year’s Day and U.S.<br />

Independence Day are no-brainers because they always occur on the same date. For these kinds of holidays,<br />

you can simply use the DATE function. To enter New Year’s Day (which always falls on January 1) for a specific<br />

year in cell A1, you can enter this function:<br />

=DATE(A1,1,1)<br />

Other holidays are defined in terms of a particular occurrence of a particular week day in a particular<br />

month. For example, Labor Day falls on the first Monday in September.<br />

Figure 13.5 shows a workbook with formulas that calculate the date for ten U.S. holidays. The formulas,<br />

which reference the year in cell A1, are listed in the sections that follow.<br />

238

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!