Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Excel: How to keep colors from the conditional formatting but delete values?

I used conditional formatting to highlight all values above 2 in a green color and below -2 in red. I now want to remove the values but keep the color present. Is there a way to do this?

I cannot simply manually highlight and use fill to do this function since I have over 6000 cells. Automation is key here!

Thanks

Update:

I cannot do AutoFilter and then highlight since by dataset is multiple columns (over 100)

1 Answer

Relevance
  • 10 years ago
    Favorite Answer

    Here is an event handler that will audit all rows, in all columns containing data, and set the fill color based on your criteria.

    Copy the following event handler to the clipboard:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim LastRow, LastCol

    LastRow = Application.Cells. SpecialCells(xlCellTypeLastCell).Row

    LastCol = Application.Cells. SpecialCells(xlCellTypeLastCell).Column

    For i = 1 To LastRow

    For j = 1 To LastCol

    If Cells(i, j).Value > 2 And IsNumeric(Cells(i, j)) Then

    Cells(i, j).Interior.ColorIndex = 4

    ElseIf Cells(i, j).Value < -2 And IsNumeric(Cells(i, j)) Then

    Cells(i, j).Interior.ColorIndex = 3

    Else

    Cells(i, j).Interior.ColorIndex = xlNone

    End If

    Next j

    Next i

    End Sub

    Select the worksheet you wish to evaluate and right click the sheet tab.

    Select 'View Code'.

    Paste the event handler into the editing area to the right.

    Close the VBE and return to the worksheet.

    Double click any cell and the fill color will be applied to numeric values, as specified. You can delete the values from any/all cells and the fill color will remain.

    If you wish to re-evaluate later, simply double click again. The fill colors will be applied to the appropriate cells, and cells with null values will have the fill color removed.

Still have questions? Get your answers by asking now.