bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Formatting > Conditional Formatting > Shading Based on Odds and Evens

Shading Based on Odds and Evens

Summary: Given a series of values in a range of cells, you may want to shade the cells based on whether the values are odd or even. Using Conditional Formatting you can make short work out of such a need. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)

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. Choose Conditional Formatting from the Tools menu. Excel displays the Conditional Formatting dialog box. (Click here to see a related figure.)
  3. Using the left-most drop-down list, choose Formula Is.
  4. In the formula area, enter =MOD(A1,2)=1. This formula will return True if the cell contains an odd value.
  5. Click on Format and change the format to reflect the formatting you want applied for cells containing odd values.
  6. In the Conditional Formatting dialog box, click the Add button.
  7. Repeat steps 3 through 5 for the second condition, but use the formula =MOD(A1,2)=0. This condition returns True if the cell contains an even value.
  8. Click on OK to apply the conditional formats to the cells.

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.

Tip #2767 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003


Don't Go in Debt for Christmas! Tired of trying to keep up with the Joneses for Christmas? Want to enjoy the season rather than dread the aftermath? Learn how you can avoid the financial traps that spring up every Christmas.
 
Check out Top Fifteen Tips for Financing Christmas today!

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)