Search code examples
excelvbaconditional-statementsconditional-formatting

How to Apply conditional formatting formula Row By Row?


Hi I have a worksheet of 1080 rows and I want to apply conditional formatting row by row to check the price increase in each row. When I am selecting the whole range and putting formula it is showing the price change in whole range, but I need it for individual item, so need it by row by row.

Worksheet Screenshot

In the image in Row 22 the price is getting increased. I want to highlight each row from 3 to 1080. I will need a VBA code for same, but not able to figure out a code to select row one by one and for applying formula in each row individually.


Solution

  • Try this code:

    Sub ApplyColorScale()
    
        Dim rng1 As Range
        Set rng1 = Range("B3:U3")
        With rng1
            .FormatConditions.Delete
            .FormatConditions.AddColorScale ColorScaleType:=3
            With .FormatConditions(1).ColorScaleCriteria(1)
                .Type = xlConditionValueLowestValue
                .FormatColor.Color = 8109667  '7039480
            End With
            With .FormatConditions(1).ColorScaleCriteria(2)
                .Type = xlConditionValuePercentile
                .Value = 50
                .FormatColor.Color = 8711167
            End With
            With .FormatConditions(1).ColorScaleCriteria(3)
                .Type = xlConditionValueHighestValue
                .FormatColor.Color = 7039480  ' 8109667
            End With
        End With
        rng1.Copy
        Dim i As Long
        For i = 4 To 10  ' 1080
           Range("B" & i & ":U" & i).PasteSpecial Paste:=xlPasteFormats, SkipBlanks:=False
        Next i
        Application.CutCopyMode = False
    End Sub
    

    ColorScaleCopy

    Is this what you need?