Color cells given in list VBA Range

sunitarobert

New Member
Joined
Oct 8, 2012
Messages
5
Hi,

Can you please help me to color cells in given list.

Column A has criteria, Column B has worksheet name, column C has cell ranges
ColumnA. COLUMNB ColumnC
Condition 1. Sheet3. A2:A3
Condition 1. Sheet4 B6

If condition 1 Red colour condition2 yellow colour etc.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
VBA Code:
Sub My_Condition()
    Dim sh As Worksheet, rng As Range, c As Range, ws As Worksheet
    Dim x
    
    Set sh = ActiveSheet

    With sh
        Set rng = .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        For Each c In rng.Cells
            x = IIf(c = "Condition 1", vbRed, IIf(c = "Condition 2", vbYellow, IIf(c = "Condition 3", vbBlue, xlNone)))
            Sheets(c.Offset(, 1).Value).Range(c.Offset(, 2).Value).Interior.Color = x
        Next c
    End With
End Sub
 
Upvote 0
VBA Code:
Sub My_Condition()
    Dim sh As Worksheet, rng As Range, c As Range, ws As Worksheet
    Dim x
   
    Set sh = ActiveSheet

    With sh
        Set rng = .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        For Each c In rng.Cells
            x = IIf(c = "Condition 1", vbRed, IIf(c = "Condition 2", vbYellow, IIf(c = "Condition 3", vbBlue, xlNone)))
            Sheets(c.Offset(, 1).Value).Range(c.Offset(, 2).Value).Interior.Color = x
        Next c
    End With
End Sub
Thanks a lot working as expected
 
Upvote 0

Forum statistics

Threads
1,216,373
Messages
6,130,230
Members
449,567
Latest member
ashsweety

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