I have an excel where I have to
remove cell fill color if existing fill color is yellow
set cell text color back to black only if existing font color is red.
I have written a macro that simply loops over each cell and checks the font color / fill color
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
...
For Each Cell In ws.UsedRange.Cells
If Cell.Font.ColorIndex = 3 Then
Cell.Font.ColorIndex = 0
End If
If Cell.Interior.ColorIndex = 6 Then
Cell.Interior.Pattern = xlNone
Cell.Interior.TintAndShade = 0
Cell.Interior.PatternTintAndShade = 0
End If
Next
It works as expected but it runs very slowly probably because it goes through each cell. Is there a to make this work faster ? I tried using conditional formatting with VBA but it cant seem to check for the cell color / cell font color...
ws.UsedRange.SpecialCells(xlCellTypeConstants).Cells
... Assuming there are no formulas in the cells, you can change this in the If For Loop. - MikkuApplication.ScreenUpdating = False
in the beginning of the code andTrue
in the end will make it significantly faster. - Mikku