Removing Conditional Formats, but Not the Effects

Written by Allen Wyatt (last updated August 25, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003


4

Charlie wondered if there is a way to "make permanent" the effects of conditional formatting at any given time. For instance, if a conditional format specifies that a particular cell be bold red type, then Charlie wanted a way to remove the conditional format and make the cell bold and red.

There is no intrinsic way to do this in Excel; none of the Paste Special options will do the task, as desired. You can, however, use a macro to accomplish the task:

Option Explicit
Sub PasteFC()
    Application.ScreenUpdating = False
    Dim rWhole As Range
    Dim rCell As Range
    Dim ndx As Integer
    Dim FCFont As Font
    Dim FCBorder As Border
    Dim FCInt As Interior
    Dim x As Integer
    Dim iBorders(3) As Integer

    iBorders(0) = xlLeft
    iBorders(1) = xlRight
    iBorders(2) = xlTop
    iBorders(3) = xlBottom

    Set rWhole = Selection

    For Each rCell In rWhole
        rCell.Select
        ndx = ActiveCondition(rCell)
        If ndx <> 0 Then
            'Change the Font info
            Set FCFont = rCell.FormatConditions(ndx).Font
            With rCell.Font
                .Bold = NewFC(.Bold, FCFont.Bold)
                .Italic = NewFC(.Italic, FCFont.Italic)
                .Underline = NewFC(.Underline, FCFont.Underline)
                .Strikethrough = NewFC(.Strikethrough, _
                  FCFont.Strikethrough)
                .ColorIndex = NewFC(.ColorIndex, FCFont.ColorIndex)
            End With
            'Change the Border Info for each of the 4 types
            For x = 0 To 3
                Set FCBorder = rCell.FormatConditions(ndx).Borders(iBorders(x))
                With rCell.Borders(iBorders(x))
                    .LineStyle = NewFC(.LineStyle, FCBorder.LineStyle)
                    .Weight = NewFC(.Weight, FCBorder.Weight)
                    .ColorIndex = NewFC(.ColorIndex, FCBorder.ColorIndex)
                End With
            Next x
            'Change the interior info
            Set FCInt = rCell.FormatConditions(ndx).Interior
            With rCell.Interior
                .ColorIndex = NewFC(.ColorIndex, FCInt.ColorIndex)
                .Pattern = NewFC(.Pattern, FCInt.Pattern)
            End With
            'Delete FC
            rCell.FormatConditions.Delete
        End If
    Next
    rWhole.Select
    Application.ScreenUpdating = True
    MsgBox ("The Formatting based on the Conditions" & vbCrLf & _
      "in the range " & rWhole.Address & vbCrLf & _
      "has been made standard for those cells" & vbCrLf & _
      "and the Conditional Formatting has been removed")
End Sub
Function NewFC(vCurrent As Variant, vNew As Variant)
    If IsNull(vNew) Then
        NewFC = vCurrent
    Else
        NewFC = vNew
    End If
End Function
Function ActiveCondition(rng As Range) As Integer
    'Chip Pearson http://www.cpearson.com/excel/CFColors.htm
    Dim ndx As Long
    Dim FC As FormatCondition

    If rng.FormatConditions.Count = 0 Then
        ActiveCondition = 0
    Else
    For ndx = 1 To rng.FormatConditions.Count
        Set FC = rng.FormatConditions(ndx)
        Select Case FC.Type
            Case xlCellValue
                Select Case FC.Operator
                    Case xlBetween
                        If CDbl(rng.Value) >= CDbl(FC.Formula1) And _
                          CDbl(rng.Value) <= CDbl(FC.Formula2) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlGreater
                        If CDbl(rng.Value) > CDbl(FC.Formula1) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlEqual
                        If CDbl(rng.Value) = CDbl(FC.Formula1) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlGreaterEqual
                        If CDbl(rng.Value) >= CDbl(FC.Formula1) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlLess
                        If CDbl(rng.Value) < CDbl(FC.Formula1) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlLessEqual
                        If CDbl(rng.Value) <= CDbl(FC.Formula1) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlNotEqual
                        If CDbl(rng.Value) <> CDbl(FC.Formula1) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case xlNotBetween
                        If CDbl(rng.Value) <= CDbl(FC.Formula1) Or _
                            CDbl(rng.Value) >= CDbl(FC.Formula2) Then
                            ActiveCondition = ndx
                            Exit Function
                        End If
                    Case Else
                        Debug.Print "UNKNOWN OPERATOR"
                End Select
            Case xlExpression
                If Application.Evaluate(FC.Formula1) Then
                    ActiveCondition = ndx
                    Exit Function
                End If
            Case Else
                Debug.Print "UNKNOWN TYPE"
        End Select
    Next ndx
    End If
    ActiveCondition = 0
End Function

There are three procedures in this solution. The last procedure, ActiveCondition, is designed to return a number indicating which of the conditions in a conditional format is currently in effect. This routine was found at Chip Pearson's site, as indicated in the first comment of the function. (No sense in re-inventing the wheel. :>))

The center function, NewFC, is simply used to determine which of two values is valid. The procedure you actually run, however, is PasteFC. Simply select the cells you want to convert to explicit formatting, then run the procedure. It checks each cell you selected for which formatting condition is active, determines the formatting of that condition, and then applies it to the cell. Finally, the conditional formatting for the cell is removed.

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 (1947) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Saving Personalized Copies of a Document

Need a series of documents that include an individual's name or a company name? Here's a handy little macro that will ...

Discover More

Numbers in Base 12

Different professions use numbers in entirely unique ways. You may need to come up with a number that represents the ...

Discover More

Specifying a Data Validation Error Message

Data validation is a great tool for limiting what can be input into a cell. Excel allows you to specify what should ...

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 (menu)

Conditionally Formatting Non-Integers

The conditional formatting capabilities of Excel are very helpful when you want to call attention to different values ...

Discover More

Sorting or Filtering by Conditional Format Results

Conditional formatting is a great feature in Excel. Unfortunately, you can't sort or filter by the results of that ...

Discover More

Conditional Formatting

One of the powerful features of Excel is the ability to format a cell based on the contents of that cell or another. It ...

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 1 + 1?

2020-05-16 04:01:42

Peter

Hi Allen,
This seems way too complicated. The .displayformat property is provided to give direct access to the conditionally set formats. For example the following sets some formats that might be set conditionally.

For Each cc In Selection
With cc
If .FormatConditions.Count > 0 Then
.Interior.Color = .DisplayFormat.Interior.Color
With .Font
.Size = cc.DisplayFormat.Font.Size
.Color = cc.DisplayFormat.Font.Color
.Bold = cc.DisplayFormat.Font.Bold
.Italic = cc.DisplayFormat.Font.Italic
End With
For ii = 7 To 12
.Borders(ii).LineStyle = .DisplayFormat.Borders(ii).LineStyle
Next ii
.FormatConditions.Delete
End If
End With
Next cc


2020-05-14 12:52:27

Anthony

Copy into word, then back in to Excel <3


2020-01-16 13:45:49

Chris Weaver

The ActiveCondition function code here does not match that of cpearson.com/excel/CFColors.htm. You are missing 2 variable definitions as well as the code execution of those 2 variables:
Dim Temp As Variant
Dim Temp2 As Variant
Temp and Temp2 are outlined for each case on cpearson.com/excel/CFColors.htm.


2019-10-18 14:29:08

JustAnotherExcelUser

You don't need to do any of this macro stuff... just save the Excel document as an html web page and open it again.
Once the opened file is the .html file the formatting won't change if you modify the cell contents. Save again with the .xlsx extension.
Thanks,
.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.