11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

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

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

4. Select B4:H9 and enter this array formula.<br />

Chapter 15: Performing Magic with Array <strong>Formula</strong>s 411<br />

Remember, to enter an array formula, use Ctrl+Shift+Enter (not just Enter).<br />

{=IF(MONTH(DATE(YEAR(B2),MONTH(B2),1))MONTH(DATE(YEAR(B2),<br />

MONTH(B2),1)-(WEEKDAY(DATE(YEAR(B2),MONTH(B2),1))-1)+<br />

{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1),””,<br />

DATE(YEAR(B2),MONTH(B2),1)-<br />

(WEEKDAY(DATE(YEAR(B2),MONTH(B2),1))-1)+<br />

{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1)}<br />

5. Format the range B4:H9 to use this custom number format: d.<br />

This step formats the dates to show only the day. Use the Custom category in the<br />

Number tab in the Format Cells dialog box to specify this custom number format.<br />

6. Adjust the column widths and format the cells as you like.<br />

Change the month and year in cell B2, and the calendar will update automatically. After creating<br />

this calendar, you can copy the range to any other worksheet or workbook.<br />

Figure 15-13: Displaying a calendar by using a single array formula.<br />

The array formula actually returns date values, but the cells are formatted to display only the day<br />

portion of the date. Also, notice that the array formula uses array constants.<br />

See Chapter 14 for more information about array constants.<br />

The array formula can be simplified quite a bit by removing the IF function, which checks to make<br />

sure that the date is in the specified month:<br />

=DATE(YEAR(B2),MONTH(B2),1)–(WEEKDAY(DATE(YEAR(B2),MONTH(B2),1))<br />

–1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}–1

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

Saved successfully!

Ooh no, something went wrong!