VBA If Statement to apply Background Colour

SimonGeoghegan

Board Regular
Joined
Nov 5, 2013
Messages
68
Hi All,

I am trying to figure out a way that I can apply a background colour to a range of cells (which will change on a monthly basis) based on the colour of the previous range of cells.

So, if the previous range of cells is coloured green, I want the new range of cells to be coloured red (and vice versa)

I can select the range of cells I need, and I know how to apply a background colour however I am struggling with understanding how I can get VBA to read the background colour of another cell and then use that to determine what colour my new range should be.

Can anybody advise of how an if statement would look for this?

The code I have got so far is:

Code:
    'Open Tabs and Copy Hospitals
'
    Sheets("Data").Visible = True
    Sheets("Data").Select
    Sheets("Brain").Visible = True
    Sheets("Brain").Select
    Range("B8:B64").Copy
    Sheets("Data").Select
    Range("A3").Select
    ActiveCell.End(xlDown).Offset(1, 0).Select
    
    'Paste Hospitals
    
    Selection.PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False


At this point, the range of cells I want to apply a background colour to is selected, however from I'm struggling.

Any help would be greatly appreciated :)

Regards,
Simon
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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