Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning a background color to a cell, given a condition on another cell

Tags:

excel

vba

I am trying to create a formula in Microsoft Excel 2010 to accomplish the following algorithm:

If A1=10, then A2 has a background color of red.

I have basic knowledge of if/then statements in Excel, so I have this so far:

=IF(A1=10, x)

...where x would be the formula for changing the background color of the cell. However, after conducting some internet research on the subject, the consensus seems to be that I should instead use conditional formatting to accomplish this task. I have never used conditional formatting and am having trouble understanding how to utilize it so that a condition on one cell would affect another cell.

This is the conditional formatting screen that I am faced with:

Conditional box

So I guess I have two questions:

  1. Is using conditional formatting the best way to accomplish this?
  2. If so, how can I utilize it to assign a background color to a cell, given the truth of a condition on a different cell?
like image 213
JSW189 Avatar asked Aug 15 '12 20:08

JSW189


People also ask

How to change the background color of cells based on cell values?

Task: You have a table or range of data, and you want to change the background color of cells based on cell values. Also, you want the color to change dynamically reflecting the data changes. Solution: You need to use Excel conditional formatting to highlight the values greater than X, less than Y or between X and Y.

How to format cells with colours in Excel?

In the New Formatting Rule box, select Format only cells that contain under Select a Rule Type. In the Rule Description choose the condition greater than or equal to and put in the value 20. Now, click on the Format to fill in the cell with colors. For this, go to the Fill tab in the Format Cells box and pick a background color.

How to change the color of blank cells with formula errors?

If you want to change the color of blank cells or cells with formula errors permanently, follow this way. Select your table or a range and press F5 to open the "Go To" dialog, and then click the "Special…" button. In the "Go to Special" dialog box, check the Blanks radio button to select all empty cells.

What is the difference between blue and green color in Excel?

This means if D3>3 then cell color should become “Blue” and if D3>5 then cell color should remain green as we did it in the previous step. Now if you follow the above steps as you did for Green color, you will see that even if the cell value is 6, it is still showing blue color and not green.


1 Answers

You can do it using conditional formatting, so you're on the right track. One thing I'm assuming here is that you want to format the cell to the right of the cell with the value - is that correct? If so, you actually don't need to use an if formula (though your logic is correct). In that dialog box, make the formula:

=A1=10

And then when you click OK, change the Applies to range by clicking on the little chart icon next to it and clicking cell B1. Then do apply, etc., close out the box and try typing 10 in A1. When you need to expand the range, you can just change that Applies to range to encompass everything you want affected. In the example below, cells B1:B26 will all change if 10 is entered in the cell directly to the left (column A).

enter image description here

like image 96
RocketDonkey Avatar answered Sep 21 '22 07:09

RocketDonkey