Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88087

Looping and offsetting for conditional formatting

$
0
0

I want my code to add conditional formatting to a range of cells.

It would highlight the entire row (I'm defining entire row from i5 to BH5 everything before it is just hidden things) red if the number in a certain cell is higher then a defined amount. It starts by checking $M5 (and checks all rows below if it is above the defined amount so M6, M7, M8,so on...), then I want it to move four columns to the right and to check $Q5.

If any of these cells are over the defined amount (we'll call it 10) then it will highlight the whole row red.

I figured I would use looping and offset as I don't want to have to type in $M5>10 $Q5>10 etc.

Sub QChelp()
    Dim colhl As Long
    Dim HLA As String
    HLA = "$M5"

    For colhl = 13 To 29 Step 4
        With Range("I5:BH300")
            .FormatConditions.Add Type:=xlExpression, Formula1:= _
              "=OR("& HLA & ">10)"
            With .FormatConditions(.FormatConditions.Count)
                .SetFirstPriority
                With .Interior
                    .PatternColorIndex = xlAutomatic
                    .ColorIndex = 3
                    .TintAndShade = 0
                End With
            End With
        End With
    Next colhl

End Sub

Viewing all articles
Browse latest Browse all 88087

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>