Comparing Dollar Values in a Conditional Formatting Rule

Written by Allen Wyatt (last updated January 6, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


3

Barbara uses conditional formatting to highlight when one number is not equal to another number. She is working with dollars, so she only cares about the numbers being equal to the penny. Since Excel looks out to more decimal places, $100.00 may not be equal to $100.00 at the fifth decimal place and conditional formatting highlights the numbers as being unequal. The only way Barbara has been able to overcome this is by writing two formatting rules saying it is OK if the difference is within a range. She wonders if there is an easier way.

The easiest solution to this is to change the formulas used to generate the values so that they are rounded. For instance, let's say you have a formula that sums a range of cells. All you need to do is to change the formula so that the result of the sum is rounded:

=ROUND(SUM(F2:F27),2)

If you are comparing rounded results in your worksheet, then you'll get the proper comparisons you desire.

Another approach is to change the formula used in your conditional formatting rules. Instead of checking if two values are equal, check if the rounded version of the two values is equal. As an example, if your conditional formatting rule compares the values stored in B6 and C6, you could change the rule to use this formula:

=ROUND(B6,2)=ROUND(C6,2)

Still another approach is to modify the precision that Excel uses. As Barbara is aware, Excel does its calculations at a high level of precision, which is why she may have problems resulting from results at the fifth decimal place. Instead, you can modify how the calculations are done in this manner:

  1. Display the Excel Options dialog box. (In Excel 2007 click the Office button and then click Excel Options. In Excel 2010 or later versions, display the File tab of the ribbon and then click Options.)
  2. At the left of the dialog box click Advanced.
  3. Scroll through the available options until you get to the section entitled "When Calculating this Workbook." (See Figure 1.)
  4. Figure 1. The Advanced options in the Excel Options dialog box.

  5. Ensure that the Set Precision As Displayed check box is selected.
  6. Click OK.

Now, Excel uses the precision shown on the screen in all of its calculations, instead of doing calculations at the full 15-digit precision it normally maintains. The benefit is that you don't have to then use the ROUND function in your formulas—you just change the formatting of the cells so that the desired number of decimal places are displayed.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9175) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

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

Selecting a Group of Words

Want to select a chunk of text in a document? Perhaps the easiest way to do this involves using the mouse in conjunction ...

Discover More

Backing Up Your AutoCorrect Entries

Develop a lot of AutoCorrect entries and you may start to wonder how you can back them up. You can easily protect all the ...

Discover More

Specifying Location for a Message Box

When writing macros, you may want to position a message box at a specific location on the screen. This can't be done in ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Conditionally Formatting for a Pattern

Conditional formatting is a great tool you can use to customzie your worksheets. When you want to test whether a value in ...

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

Conditionally Highlighting Cells Containing Formulas

Excel's conditional formatting feature allows you to create formats that are based on a wide variety of criteria. If you ...

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}] (all 7 characters, in the sequence shown) 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 2 + 8?

2024-01-08 17:24:10

Dave Bonin

I sometimes use ABS( B6 - C6 ) < 0.001

This keeps it a one-way comparison and it doesn't matter which value might be slightly bigger or smaller.


2024-01-06 18:16:44

Dave

Your two methods could give you different results since precision as displayed rounds before summing.


2024-01-06 10:11:41

J. Woolley

My Excel Toolbox includes the PrecisionAsDisplayed() function to return the status of a workbook's calculation precision (TRUE if 'AsDisplayed' or FALSE if 'Standard'). For example:
="Precision is "&IF(PrecisionAsDisplayed(),"'AsDisplayed'","'Standard'")
My Excel Toolbox also includes the TogglePrecision macro to switch between the two possibilities.
See https://sites.google.com/view/MyExcelToolbox/
For more on this subject, see https://excelribbon.tips.net/T013765_Permanently_Turning_On_Set_Precision_As_Displayed.html


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.