excel2007.Tips.Net Welcome toExcel2007.Tips.Net

Helpful Links

Excel 2007 Home
Tips.Net Home

Ask a Question
Make a Comment

Cooking Tips
Gardening Tips
Legal Tips
WordTips

Newest Tips

Changing a Link's Source

Using Conditional Formatting to Shade Rows

Editing by Moving and Copying

Making Sure Duplicate Names Aren't Entered

Applying a Conditional Format to a Full Row

Hiding Worksheet Tabs

Making Cells Flash

 

Shading Odd and Even Values

Summary: You can use conditional formatting to add shading to various cells in your worksheet. This tip shows how you can shade cells based on whether a value is odd or even.

If you have a series of values in a range of cells, you might want to use different formatting to differentiate the odd numbers from the even numbers. The way you do this is through the use of the Conditional Formatting feature in Excel. Follow these steps:

  1. Select the cells that contain the odd and even values.
  2. With the Home tab of the ribbon displayed, click the Conditional Formatting option in the Styles group. Excel displays a palette of options related to conditional formatting.
  3. Click Manage Rules. Excel displays the Conditional Formatting Rules Manager dialog box.
  4. Click New Rule. Excel displays the New Formatting Rule dialog box.
  5. In the Select a Rule Type area at the top of the dialog box, choose Use a Formula to Determine Which Cells to Format. (Click here to see a related figure.)
  6. In the Format Values Where This Formula Is True box, enter the following: =MOD(A1,2)-1. This formula will return True if the cell contains an odd value.
  7. Click Format to display the Format Cells dialog box.
  8. Using the controls in the dialog box, specify a format that you want used for those cells that contain an odd value.
  9. Click OK to dismiss the Format Cells dialog box. The formatting you specified in step 7 should now appear in the preview area for the rule.
  10. Click OK. The New Formatting Rule dialog box disappears and Excel again displays the Conditional Formatting Rules Manager dialog box. The rule you just defined is listed in the dialog box.
  11. Repeat steps 4 through 10 for the second condition, but use the formula =MOD(A1,2)=0. This formula returns True if the cell contains an even value.
  12. Click OK. Excel applies the conditional formatting to the cells you selected in step 1.

With this conditional formatting applied, if the cell is odd it will be one color and if even it will be another. If the cell contains text, the cell will be uncolored, meaning it will have the color of the cell before you added the conditional formatting. The conditional formatting overrides any formatting you put on the cell, so even if you try to change the cell color via the toolbar, the conditional formatting takes precedence.

It is interesting to note that if you have the Analysis ToolPak enabled in Excel, you might be tempted to use the ISODD and ISEVEN functions in the conditional format. These functions cannot apparently be used with conditional formatting. If you try to do so, Excel generates an error that says "You may not use references to other worksheets or workbooks for Conditional Formatting criteria." The best bet is to use the MOD function, as described above.

Related Tips:

Create and Merge! Using Word's mail merge tool you can quickly and easily combine data from a variety of data sources to create great individualized documents that incorporate your data in ways that you control. WordTips: Mail Merge Magic is an invaluable source for learning how to harness the full power of Word's mail merging capabilities. Check out WordTips: Mail Merge Magic today!