Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Shading Based on Odds and Evens.

Shading Based on Odds and Evens

by Allen Wyatt
(last updated November 21, 2015)

2

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. (In Excel 2013 and Excel 2016, click on New Rule and then select Use a Formula to Determine Which Cells to Format.) (See Figure 1.)
  6. Figure 1. The New Formatting Rule dialog box.

  7. 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.
  8. Click Format to display the Format Cells dialog box.
  9. Using the controls in the dialog box, specify a format that you want used for those cells that contain an odd value.
  10. 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.
  11. 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.
  12. 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.
  13. Click the up and down arrows to move the rules you created to the order in which they should be evaluated.
  14. 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 tools on the ribbons, the conditional formatting takes precedence.

The MOD function isn't the only thing you can use in your formula. If you want to determine whether the cell contains an odd value (step 6), you could use the following:

=ISODD(A1)

Similarly, if you want to determine if the cell contains an even value (step 11), you could use the following:

=ISEVEN(A1)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6260) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Shading Based on Odds and Evens.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Checking for Valid Hyperlinks

If you have a document containing a lot of hyperlinks, it would be cool if there was a way to check all those hyperlinks and ...

Discover More

Reducing File Sizes for Workbooks with PivotTables

Need to reduce the size of your workbooks that contain PivotTables? Here's something you can try to minimize the ...

Discover More

Quickly Finding Synonyms

If you need to find some synonyms for a specific word in your document, here's how you can do it. (Hint: All you need to do ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Conditional Page Breaks

Need to have your worksheet printout start on a new page every time a value in a column changes? There are a couple of ways ...

Discover More

Highlighting Values that are 10x a Baseline Value

Sometimes the hardest part of getting your conditional formatting rules to work properly is figuring out the proper way to ...

Discover More

Conditionally Formatting Cells Containing Dates

Need to know if a particular cell contains a date value? Excel doesn't have a worksheet function to determine this ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 9?

2015-11-23 05:07:57

DaveS

Richard
I think the example assumes that the range starts in A1. If the first cell in your range is something other than A1 you need to substitute its reference for A1 in the formula.


2015-11-23 04:23:43

Richard

There seems to be no correlation between the range of cells selected and the formula, unless there's an unstated assumption that the range of cells begins at A1.
How does Excel know which of the selected cells to apply the formula to?
Does it not matter what cell reference I use in the formula? What about when I want to apply different conditions to different ranges?


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.