DNayan
DNayan

Reputation: 1

How to change specific cell colours to No Fill across multiple tabs in Excel?

I am currently trying to change Cells across several worksheets in a Workbook which have a specific colour to No Fill. Here is the code I am using below. Can anyone help?

Sub YellowFillToNoFill()
        'RGB(246, 244, 150) Yellow Colour To change to no Fill

       'PURPOSE: Change any cell with a Yellow fill color to a No fill color

        Dim cell As Range

       'Optimize Code
        Application.ScreenUpdating = False

        'Ensure Cell Range Is Selected
        If TypeName(Selection) <> "Range" Then
        MsgBox "Please select some cells before running"
        Exit Sub
        End If

       'Loop Through Each Cell
        For Each cell In ActiveSheet.UsedRange 'Can also use Range("C1,C2" etc.) instead of 
        'Selection.Cells' or 'ActiveSheet.UsedRange'
          If cell.Interior.Color = RGB(246, 244, 150) Then
          cell.Interior.Color = xlNone
          End If
        Next
End Sub

Upvotes: 0

Views: 157

Answers (1)

FunThomas
FunThomas

Reputation: 29612

To reset the value, use Use cell.Interior.ColorIndex = xlNone

Color defines the color that is displayed. It's a long value that contains the RGB-value of the color.

ColorIndex is the index into the table of predefined colors (the table of colors you see when you select a color in Excel). The special value xlNone (-4142) removes any color setting.

Upvotes: 1

Related Questions