This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion...

6

Transcript of This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion...

Page 1: This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion created by specific formatting. It is easy to create this illusion yourself by applying
Page 2: This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion created by specific formatting. It is easy to create this illusion yourself by applying
Page 3: This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion created by specific formatting. It is easy to create this illusion yourself by applying

This excerpt is protected by copyright law. It is your responsibility to obtain permissions necessary for any

proposed use of this material. Please direct your inquiries to [email protected].

Page 4: This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion created by specific formatting. It is easy to create this illusion yourself by applying

58 | Chapter 2, Hacking Excel’s Built-in Features

#21 Highlight Every Other Row or ColumnHACK

to the first cell on the worksheet. Copy this across to cell D1, and youshould have a double copy of your column A heading. These copies will beused as headings for your DSUM criteria (C1:D2), which you calledSumCriteria.

In cell C2, enter >10. In cell D2, enter <20. In the cell where you want yourresult, enter the following formula:

=DSUM($A$1:$A$100,$A$1,SumCriteria)

DSUM is the preferred and most efficient method of working with cells thatmeet certain criteria. Unlike arrays, the built-in database functions aredesigned specifically for this purpose, and even when they reference a verylarge range and are used in large numbers, the negative effects they have onrecalculation speed and efficiency are quite small compared to those of arrayformulas.

H A C K

#21Highlight Every Other Row or Column Hack #21

You’ve surely seen Excel spreadsheets that have alternating row colors. Forinstance, odd-numbered rows might be white, while even-numbered rowsmight be gray. Conditional formatting makes this easy.

Alternating colors or shading looks professional and can make data easier toread. You can apply this formatting manually, but as you can imagine, ormight have experienced, it’s a rather time-consuming task that requires con-stant updating as you add and remove data from the table. It also requiresinfinite patience. Fortunately, conditional formatting can reduce the amountof patience required and enhance your professional image.

We’ll assume your data occupies the range A1:H100. Select this range ofcells, starting with A1, thus ensuring that A1 is the active cell in the selec-tion. Now select Home ➝ Conditional Formatting ➝ New Rule ➝ “Use a for-mula to determine which cells to format,” and type the following formula inthe “Format values where this formula is true” box (pre-2007, go to Format➝ Conditional Formatting… ➝ change “Cell Value Is” to “Formula Is”), asshown in Figure 2-5:

=MOD(ROW( ),2)

Click the Format button and choose the format you want to apply to everysecond row. Click OK, and then click OK again. The format you specifiedshould be applied to every second row in the range A1:H100. You alsoshould have some patience left for the rest of the day.

If you need to apply this to columns rather than rows, use this formulainstead:

=MOD(COLUMN( ),2)

Page 5: This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion created by specific formatting. It is easy to create this illusion yourself by applying

Highlight Every Other Row or Column #21

Chapter 2, Hacking Excel’s Built-in Features | 59

HACK

Although this method applies the formatting specified to every second rowor column quickly and easily, it is not dynamic. Rows containing no datawill still have the formatting applied. This looks slightly untidy and makesreading the spreadsheet a bit more difficult. Making the highlighting ofevery second row or column dynamic takes a little more formula tweaking.

Highlighting DynamicallyAgain, select the range A1:H100, ensuring that A1 is the active cell. SelectHome ➝ Conditional Formatting ➝ New Rule ➝ “Use a formula to deter-mine which cells to format,” and in the “Format values where this formula istrue” box (pre-2007, go to Format ➝ Conditional Formatting… ➝ change“Cell Value Is” to “Formula Is”), type the following formula:

=AND(MOD(ROW( ),2),COUNTA($A1:$H1))

Note that you do not reference rows absolutely (with dollarsigns), but you do reference columns this way.

Click the dialog’s Format option and select the desired formatting, then clickOK, and OK again. Any row within the range A1:H100 that does notcontain data will not have conditional formatting applied. If you remove

Figure 2-5. New Formatting Rule dialog containing the MOD formula to specify aformat to every second row in a range

Page 6: This excerpt is protected by copyright law. It is your...Excel, you are actually seeing an illusion created by specific formatting. It is easy to create this illusion yourself by applying

60 | Chapter 2, Hacking Excel’s Built-in Features

#22 Create 3-D Effects in Tables or CellsHACK

data from a specific row in your table, it too will no longer have conditionalformatting applied. If you add new data anywhere within the range A1:H100, the conditional formatting will kick in.

This works because when you supply a formula for conditional formatting,the formula itself must return an answer of either TRUE or FALSE. In the lan-guage of Excel formulas, 0 has a Boolean value of FALSE, while any nonzerovalue has a Boolean value of TRUE. When you use the formula =MOD(ROW( ),2),it will return either a value of 0 (FALSE) or a number greater than 0.

The ROW( ) function is a volatile function that always returns the row num-ber of the cell it resides in. You use the MOD function to return the remainderafter dividing one number by another. In the case of the formula you used,you are dividing the row number by 2, so all even row numbers will return 0,while all odd row numbers will always return a number greater than 0.

When you nest the ROW( ) function and the COUNTA function in the AND func-tion, it means you must return TRUE (or any number greater than 0) to boththe MOD function and the COUNTA function for the AND function to return TRUE.Note that COUNTA counts all nonblank cells.

H A C K

#22Create 3-D Effects in Tables or Cells Hack #22

Whenever you see a nifty 3-D effect in a program or application such asExcel, you are actually seeing an illusion created by specific formatting. It iseasy to create this illusion yourself by applying formatting to a cell or rangeof cells. The release of Excel 2007 introduces cell styles, so you can create a3-D effect and save it to use anytime you like.

To start off with a simple example, we’ll give a cell a 3-D effect so that itappears raised, like a button. On a clean worksheet, select cell D5. (You’reselecting D5 because it’s not on an edge.) Under the Cells options on theHome tab, select Format ➝ Format Cellst ➝ Border (pre-2007, Format ➝

Cells ➝ Border). From the Line box, choose the second thickest line style.Ensure that the color selected is black (or Automatic, if you haven’t changedthe default for this option). Now click the right-hand border and then clickthe bottom border. Return to the color option and select white. The secondthickest border still should be selected, so this time click the two remainingborders of the cell, the top border and the left border. Click the Fill tab (pre-2007, the Patterns tab) in the Format Cells dialog and make the cell shadinggray. Click OK and deselect cell D5. Cell D5 will have a raised effect thatgives the appearance of a button. You did it all with borders and shading.

If, for fun or diversity, you want to make a cell look indented or pushed in,select cell E5 (because it’s next to D5 and it makes the next exercise work).Select Home ➝ Cells ➝ Format ➝ Format Cells ➝ Border (pre-2007, Format