Color cell background off list and then using offset

akaitsuki

New Member
Joined
Aug 17, 2016
Messages
8
Sub color_country()


country = Columns("C:C").Select


Select Case country
"CL" , "MX", "CO"
Case Is = ActiveCell.Interior.color = RGB(255, 0, 0)
Case Else


End Sub


Couldn't quite get this to work the way I wanted to. I have a list of countries in column C that I want the background of the cell to be red. Once that is done, if a cell in column C is red, I went the cell in column P to be a 0.

Anyone have advice? Sorry I'm really bad at this. :(
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
[color=darkblue]Sub[/color] color_country()
    
    [color=darkblue]Dim[/color] rngC [color=darkblue]As[/color] Range, country [color=darkblue]As[/color] Range
        
    [color=darkblue]Set[/color] rngC = Range("C1", Range("C" & Rows.Count).End(xlUp))
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] country [color=darkblue]In[/color] rngC
        [color=darkblue]Select[/color] [color=darkblue]Case[/color] country.Value
            [color=darkblue]Case[/color] "CL", "MX", "CO"
                country.Interior.Color = vbRed
                country.Offset(0, 13).Value = 0
            [color=darkblue]Case[/color] [color=darkblue]Else[/color]
        [color=darkblue]End[/color] [color=darkblue]Select[/color]
    [color=darkblue]Next[/color] country
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Hello akaitsuki,

Try this...

Code:
Sub Color_Country()
    
    Dim Cell As Range
    
        For Each Cell In Range("C1", Cells(Rows.Count, "C").End(xlUp))
            Select Case Cell.Value
                Case Is = "CL", "MX", "CO"
                    Cell.Interior.Color = RGB(255, 0, 0): Cell.Offset(0, 13).Value = 0
            End Select
        Next C

End Sub
 
Upvote 0
Here is a non-looping macro that should work quite quickly for you, especially if you have a larger amount of row to process...
Code:
[table="width: 500"]
[tr]
	[td]Sub SetColumnBfromColumnA()
  Application.ScreenUpdating = False
  ActiveSheet.AutoFilterMode = False
  Rows(1).Insert
  Columns("C").AutoFilter Field:=1, Criteria1:=Array("CL", "CO", "MX"), Operator:=xlFilterValues
  On Error GoTo NothingVisible
  With Intersect(ActiveSheet.UsedRange, Columns("C").SpecialCells(xlVisible))
    .Interior.Color = vbRed
    .Offset(, 1) = 0
  End With
  ActiveSheet.AutoFilterMode = False
NothingVisible:
  Rows(1).Delete
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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