Change Cell Fill Color if Cell has Text and No Fill Color

btb918

New Member
Joined
Aug 17, 2017
Messages
2
Office Version
  1. 2019
  2. 2016
  3. 2013
I don't believe conditional formatting based on a cell's fill color is an option so that leaves only macros.

I'd like to specify a range of cells in which if I type something into any one of those cells, it's fill color will change to "green". If I then change the fill color to "red" it will stay "red" and not still be "green". Any suggestions? Thanks in advance.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This will change the background in for A2 to A22 if a change is made
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A2:A22")) Is Nothing And Target.Count = 1 Then

Target.Interior.Color = vbGreen
End If
End Sub
 
Upvote 0
Just a slight modification on Fluff's code to account for if the cell is red:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A2:A22")) Is Nothing And Target.Count = 1 Then
        If Target.Interior.Color <> vbRed Then 'If the interior cell color is not red then....
            Target.Interior.Color = vbGreen 'Change the interior cell color to green
        End If
    End If
End Sub
 
Upvote 0
btb918
If the cell is red & you change the value, should it
a) remain red - Use the code from mrmmickle
b) change to green - use my code
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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