Conditional Formatting Not Reliably Working

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


4

David creates and distributes several large reports every week, averaging 100 rows and 66 columns. He uses Conditional Formatting to highlight information in about a dozen columns. Every week he must check all the cells to which Conditional Formatting is applied because some of the cells don't format when the data require they should. This doesn't affect all the cells, and it's not the same cells every week. Hence, David must check all of them. This is very time consuming, of course, so he wonders what he must do to make sure that Conditional Formatting behaves as it should.

There is a very good chance that Conditional Formatting is behaving as it should. I have never had any instances of Conditional Formatting rules changing on their own, and any fragmentation of the rules that I've experienced have been attributable to me (or someone else) copying and pasting information that affected those rules.

Let me provide an example: Let's say that I have a Conditional Formatting rule applied to column M. If it applies to the entire column, then deleting or inserting rows won't affect it. What would affect it, however, is if I copy a value from column C and paste that value into column M. The default method of pasting information is to paste both the value and any formatting applied to the source cell. This overwrites any formatting in the target cell, including any Conditional Formatting.

After the pasting, my Conditional Formatting rule no longer applies to all of column M. I now have a rule for all cells above where I pasted and the same rule for the cells below where I pasted. I have, in other words, fragmented my Conditional Formatting in column M, and that may present a problem like what David is experiencing.

There is no way to "lock" Conditional Formatting so that it cannot be overwritten as just described. Users can remember to only paste values (sans formatting), which would solve the issue, but there is no way to ensure that they do so. You can protect the worksheet, but that may affect other editing operations that you need to allow within it.

The best solution I've found is to create a macro that will reapply all the Conditional Formatting you need within the worksheet. In David's case, he has Conditional Formatting applied in about a dozen columns. A macro could be written to (1) remove all Conditional Formatting rules from the worksheet and (2) define and apply the proper Conditional Formatting rules to those columns. Here's a simple example to illustrate how this could work:

Sub SetRules()
    Dim rMyRange As Range

    ' Delete all Conditional Formatting in worksheet
    Cells.FormatConditions.Delete

    Set rMyRange = Columns("M:M")

    ' Define the Conditional Formatting rule for the range
    rMyRange.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:="=2000"
    With rMyRange.FormatConditions(1)
        .SetFirstPriority
        .Font.Color = -16383844
        .Font.TintAndShade = 0
        .Interior.PatternColorIndex = xlAutomatic
        .Interior.Color = 13551615
        .Interior.TintAndShade = 0
        .StopIfTrue = False
    End With
End Sub

This example first deletes all the Conditional Formatting rules in the worksheet and then sets a single rule for column M. The easiest way to determine how to set up a Conditional Formatting rule via macro is to use the macro recorder. You can then condense and distill the lines generated by the recorder to get just the rule you desire, as was done in the above example. Running the macro is very, very fast, and it ensures that your desired Conditional Formatting rules are applied where they should be in your worksheet.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13934) 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

Stopping Smart Tags from Being Saved

Don't want Smart Tag information saved with your document? It's easy to make sure that Word doesn't save it, as described ...

Discover More

Combining Numbers and Text in a Cell

There are times when it can be beneficial to combine both numbers and text in the same cell. This can be easily done ...

Discover More

Adding Tags to Text

The Find and Replace capabilities of Word can be used to add HTML tags to your document text. This is easier to do than ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Conditionally Formatting for Multiple Date Comparisons

When you compare dates in a conditional formatting rule, you need to be careful how you put your comparisons together. Do ...

Discover More

Turning a Cell Red when a Threshold is Exceeded

Excel provides a great conditional formatting capability that allows you to change how a cell appears based on critiera ...

Discover More

Conditional Formatting for Errant Phone Numbers

Conditional formatting can be used to draw attention to all sorts of data based upon the criteria you specify. Here's how ...

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 8 - 5?

2024-07-30 00:35:30

Philip

Using Tables (where possible) will also avoid this issue ... set a Conditional Format to a column or multiple columns, and when your Table grows or shrinks the Conditional Format rule will remain limited to the specific column(s), no additional rules are added.


2024-07-28 09:58:48

J. Woolley

Like many, I’ve been frustrated when my carefully crafted conditional formatting becomes corrupted after innocently performing a copy/paste or some other such sin. And Excel’s miserable Conditional Formatting Rules Manager makes it a chore to fix the mangled rules. So My Excel Toolbox includes recently updated macros to backup and restore the active sheet’s conditional formatting using named ranges that auto-adjust to row/column changes. Run the CFBackup macro before your conditional formatting rules are broken. If they later become broken, run CFRestore.
My Excel Toolbox also includes the following dynamic array function:
    =ListFormatConditions([AllSheets], [SkipHeader])
This function returns Applies To Range, Type, and Stop If True for each conditional format. When using pre-2021 versions of Excel without support for dynamic arrays, review the PDF file UseSpillArray.pdf.
See https://sites.google.com/view/MyExcelToolbox/
For related discussion, see https://excelribbon.tips.net/T011361
and see my 2021-08-14 comment here: https://excelribbon.tips.net/T001143


2024-07-27 18:07:00

Erik

When I insert rows in the middle of a range containing conditional formatting, I've found doing this keeps the conditional formatting continuous:
1) insert the new row(s)
2) highlight and copy one old row
3) highlight all the new row(s) and paste special - equations only
4) with the new row(s) still highlighted, paste special - formats only


2024-07-27 13:21:05

Ron S

Copy/Pasting with formatting. Yah, that would explain it, Excel trying to maintain the pasted formatting.

Now I know what to avoid.

I was manually resetting the range on the first of the fractured rules, then manually deleting the rest of rule fragments. Time consuming. Macro is better. Manually deleting rules sometimes causes sheet to lock up.


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.