Page 391 - Excel 2007 Bible
P. 391

23_044039 ch18.qxp  11/21/06  11:09 AM  Page 348
                                   Part II
                                              Working with Formulas and Functions
                                                       This workbook is available on the companion CD-ROM. The file is named array formula
                                      ON  the  CD-ROM
                                      ON  the  CD-ROM
                                                       calendar.xlsx.
                                             To create this calendar in the range B2:H9, follow these steps:
                                                 1. Select B2:H2 and merge the cells by choosing Home ➪ Alignment ➪ Merge & Center.
                                                 2. Enter a date into the merged range. The day of the month isn’t important.
                                                 3. Enter the abbreviated day names in the range B3:H3.
                                                 4. Select B4:H9 and enter this array formula. Remember, to enter an array formula, use
                                                    Ctrl+Shift+Enter (not just Enter).
                                                    {=IF(MONTH(DATE(YEAR(B2),MONTH(B2),1))<>MONTH(DATE(YEAR(B2),
                                                    MONTH(B2),1)-(WEEKDAY(DATE(YEAR(B2),MONTH(B2),1))-1)+
                                                    {0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1),””,
                                                    DATE(YEAR(B2),MONTH(B2),1)-(WEEKDAY(DATE(YEAR(B2),MONTH(B2),1))-1)+
                                                    {0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1)}
                                                 5. Format the range B4:H9 to use this custom number format: d. This step formats the dates to
                                                    show only the day. Use the Custom category in the Number tab of the Format Cells dialog box to
                                                    specify this custom number format.
                                                 6. Adjust the column widths and format the cells as you like.
                                             Change the month and year in cell B2, and the calendar will update automatically. After creating this calen-
                                             dar, you can copy the range to any other worksheet or workbook.
                                       FIGURE 18.11
                                      Displaying a calendar by using a single array formula.

                                             The array formula actually returns date values, but the cells are formatted to display only the day portion of
                                             the date. Also, notice that the array formula uses array constants.
                                       CROSS-REF       See Chapter 17 for more information about array constants.
                                       CROSS-REF









                                      348
   386   387   388   389   390   391   392   393   394   395   396