VBA to highlight row based on a cell within row

Guitarmageddon

Board Regular
Joined
Dec 22, 2014
Messages
159
Hello all. Many thanks to @Fluff for getting me sorted in some other steps within this current macro.

I would like to add some VBA in at the end of my macro that does two different sets of highlights:
1.) highlight the entire row if the site number in Column M equals 60001 OR 70001. I want this DARK purple
2.) Highlight the entire row if the site number in column M equals 16001. I want this LIGHT purple.
I have given a quick example of some of the highlights below.

Notes:
My report length is dynamic, but you can reference column A since that will always go down to the end of the report
My number of columns extends out to AC, which I believe is 29 columns total on the report. If possible Id like to confine the highlight to that.



SNIP.PNG


I had something similar in another macro I had (based on some unrelated values), but it was really hard for me to dissect and repurpose since I cant remember what I did! Id appreciate any help greatly here from the masters!
VBA Code:
   Range("A2").Select
    Columns("l:l").ColumnWidth = 10.14
    Do While ActiveCell.Offset(0, 12) <> ""
       If ActiveCell.Offset(0, 12).FormulaR1C1 <> "000" Then
           Range(ActiveCell, ActiveCell.Offset(0, 42)).Select
               With Selection.Interior
                   .Pattern = xlSolid
                   .PatternColorIndex = xlAutomatic
                   .Color = 65535 'yellow
                   .TintAndShade = 0
                   .PatternTintAndShade = 0
               End With
       End If
       ActiveCell.Offset(1, 0).Select
       
    Loop
 
You can modify the macro I supplied like
Rich (BB code):
   With ActiveWorkbook.Sheets("Page1")
      For Each Cl In .Range("N9:N" & .Range("M" & Rows.Count).End(xlUp).Row)
         Cl.Value = Dic(Cl.Offset(, -1).Value)
         Select Case Cl.Offset(, -1).Value
            Case 60001, 70001
               Cl.Offset(, -12).Resize(, 29).Interior.Color = 10498160
            Case 16001
               Cl.Offset(, -12).Resize(, 29).Interior.Color = 16737996
         End Select
      Next Cl
   End With
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This is probably better as it clears those that do not match.

Code:
Sub HighlightRows()
'1.) highlight the entire row if the site number in Column M equals 60001 OR 70001. I want this DARK purple
' 2.) Highlight the entire row if the site number in column M equals 16001. I want this LIGHT purple.

Dim lRow As Long
Dim RowLoop As Long


lRow = Cells(Rows.Count, "M").End(xlUp).Row

For RowLoop = 1 To lRow
    If Range("M" & RowLoop).Value = 60001 Or Range("M" & RowLoop).Value = 70001 Then
        'dark purple
         Rows(RowLoop & ":" & RowLoop).Interior.Color = 10498160
    ElseIf Range("M" & RowLoop).Value = 16001 Then
        'light purple
        Rows(RowLoop & ":" & RowLoop).Interior.Color = 16737996
    Else
        Rows(RowLoop & ":" & RowLoop).Interior.Pattern = xlNone
    End If

Next RowLoop

End Sub
 
Upvote 0
One small modification @nemmi69

If I wanted the dark purple to be this
VBA Code:
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent4
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With

And the light purple to be this
VBA Code:
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent4
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With

How do I do that? I couldnt figure out the straight color code for them, so I just make a quick macro and selected the color preset in the fills menu, and that was the code for those colors.....
 
Upvote 0
The dark purple is 13082801
and the light is 15523812
 
Upvote 0
I ran your code & then in the Immediate window i put ?activecell.Interior.Color& pressed enter.
Then ran the other ode & did the same
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top