Home > Software engineering >  Conditional formatting macro
Conditional formatting macro

Time:11-28

So every cell that has a value of 0, that row will be hidden. And any value that is outside the minimum and maximum values ​​will be red.

How to identify red color but active (not hidden) with macro? because I used "range. displayformat. interior. color = vbred", the cells are red but hidden are also counted. Thanks.

CodePudding user response:

Try this, the visible cells will be formatted

Set rng = Range("Your range").SpecialCells(xlCellTypeVisible)
        rng = ActiveCell.DisplayFormat.Interior.Color = vbRed

CodePudding user response:

Here is the sample code for the "if" condition that you ask for.

Sub Highlight_Greater_Than()

Dim ws As Worksheet
Dim Rng As Range
Dim ColorCell As Range

Set ws = Worksheets("Name")
Set rng = Range("Your range").SpecialCells(xlCellTypeVisible)
    'rng = ActiveCell.DisplayFormat.Interior.Color = vbRed
Set ColorCell = rng

For Each ColorCell In Rng
If ColorCell.Value > 1 Then      " You can define here"  "greater, smaller, equal  etc.."
ColorCell.Interior.Color = vbred

Else
ColorCell.Interior.ColorIndex = "vb(colour)or" xlNone
End If
Next

End Sub
  • Related