Automatically Changing the Fill Color Based on a Value to the Right of it

thefastlane

New Member
Joined
Aug 13, 2014
Messages
12
Hey,
I was wondering how to set the fill color in a range("A2:C2") based on what C2 said(e.g-"Yes"). I know how to do this step..

If Sheet1.Range("C2") = "Yes" Then
Sheet1.Range("A2:C2").Interior.Color = RGB(0, 176, 240)
Sheet1.Range("A2:C2").Font.Color = RGB(0, 51, 0)
End If

It's automatically doing this for my entire sheet that's confusing. Basically, for every "yes" in column C, I want it and the two cells next to it to be a certain color. Any ideas?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hey,
I was wondering how to set the fill color in a range("A2:C2") based on what C2 said(e.g-"Yes"). I know how to do this step..

If Sheet1.Range("C2") = "Yes" Then
Sheet1.Range("A2:C2").Interior.Color = RGB(0, 176, 240)
Sheet1.Range("A2:C2").Font.Color = RGB(0, 51, 0)
End If

It's automatically doing this for my entire sheet that's confusing. Basically, for every "yes" in column C, I want it and the two cells next to it to be a certain color. Any ideas?
Take a look at conditional formatting - no VBA required.
 
Upvote 0
I initially started with conditional formatting, but ran into the same problem I'm running into now with vba. I have hundreds of rows of data, and it would take forever and a half to code or conditional format each individual row. And no, that's all the code I'm using.
 
Last edited:
Upvote 0
I know there's nothing wrong with the code, but since I have hundreds of rows of data I'd like to automatically do it.
 
Upvote 0
I misread your statement. I'm sorry. The code will be:

Code:
For x = 2 to 1000 'Change this to your max row
[COLOR=#333333]     If UCase(Sheet1.Cells(x, 3)) = "YES" Then[/COLOR]
[COLOR=#333333]          Sheet1.Range(Cells(x, 1),Cells(x, 3)).Interior.Color = RGB(0, 176, 240)[/COLOR]
[COLOR=#333333]          [/COLOR][COLOR=#333333]Sheet1.Range(Cells(x, 1),Cells(x, 3)).[/COLOR][COLOR=#333333]Font.Color = RGB(0, 51, 0)[/COLOR]
[COLOR=#333333]     End If
[/COLOR]Next x


I thought you were saying the code was making the whole sheet blue and that didn't make sense to me.
 
Upvote 0
I initially started with conditional formatting, but ran into the same problem I'm running into now with vba. I have hundreds of rows of data, and it would take forever and a half to code or conditional format each individual row. And no, that's all the code I'm using.
You don't need to do each row individually when using CF. Try this:
1. Select the entire range of interest. Let's say that's A2:C1000 for this example.
2. Home>Conditional Formatting> New Rule > Use a Formula
3. formula is: =C2="Yes"
4. Set the fill and font formats you want
5. Click OK
 
Upvote 0
You don't need to do each row individually when using CF. Try this:
1. Select the entire range of interest. Let's say that's A2:C1000 for this example.
2. Home>Conditional Formatting> New Rule > Use a Formula
3. formula is: =C2="Yes"
4. Set the fill and font formats you want
5. Click OK

Ohh ok! I thought Excel would have a way to do that in CF..
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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