VBA change Background colour based on cell Value

blossomthe2nd

Active Member
Joined
Oct 11, 2010
Messages
450
Hi Guys

I am looking for a bit a code that changes the Background colour of a cell if the value is "B"

I wish for the following to happen,
Within Range B3 : DT367
If the cell is grey (15) and has the value "B" in it ,
Change the cell to No back ground and the value to "bananas"

I have tried the following but to no avail , Please help

Thanks
A

For Each cell In Range("B3:DT367")
If cell.Value = "B" Then cell.Value = "Bananas"
Next cell
For Each cell In Range("B3:DT367")
If cell.Value = "B" Then cell.Interior.ColorIndex = xlNone
Next cell
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
For Each cell In Range("B3:DT367")
If cell.Value = "B" Then cell.Value = "Bananas"
Next cell
For Each cell In Range("B3:DT367")
If cell.Value = "B" Then cell.Interior.ColorIndex = xlNone
Next cell

Got It!!!

the cell value is now bananas so second part should reference bananas NOT "B"

Thanks
 
Upvote 0
Try

Code:
For Each cell In Range("B3:DT367")
    If cell.Value = "B" And cell.Interior.ColorIndex = 15 Then
        cell.Value = "Bananas"
        cell.Interior.ColorIndex = xlNone
    End If
Next cell
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,507
Members
452,917
Latest member
MrsMSalt

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