Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I set conditional formatting on a particular cell that depends on another cell's value?

A | B
1 | x
2 | 
3 | 
1 | x
1 | x
4 | 
8 |

// X can be any value and is here merely to
// mark the cell that should be formatted

In my example I would like to conditionally format column B cells. Those marked with x should be formatted according to value in column A (in the example the value is 1).

Value in B is not supposed to be x I just marked those cells that way here. They may contain any value actually. I just wanted to mark those cells that I want to conditionally format because there's a particular value in sibling column A.

Conditional formatting = cell style formatting (text/background colour) based on some condition.

IMPORTANT 2014 NOTE: Conditional formatting based on formula that may include other cells is now possible in Google Sheets, and works very much similar to how Excel spreadsheets work. This answer explains its use.

share|improve this question

migrated from superuser.com Jul 1 '11 at 15:33

This question came from our site for computer enthusiasts and power users.

Since you added that 2014 note, please consider also moving the checkmark to an answer that describes the modern approach. – ᴡᴏʀᴅs Oct 12 '15 at 20:49
up vote 46 down vote accepted

Complex conditional formatting can be achieved in Google Spreadsheets using Google Apps Script. For example, you could write a function that changes the background colour of an entire row based on the value in one of its cells, something that I do not think is possible with the "Change color with rules" menu. You would probably want to set triggers for this function such as "On Edit", "On Open" and "On Form Submit".

Documentation for setBackgroundRGB() function

UPDATE: Here is a Google Apps Script example of changing the background color of an entire row based on the value in column A. If value is positive, use green. If empty, white. Otherwise, red. See the results in this public Google Spreadsheet. (You will have to be signed in for the script to run, but without signing in you can still see results).

function colorAll() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;
  var endRow = sheet.getLastRow();

  for (var r = startRow; r <= endRow; r++) {

function colorRow(r){
  var sheet = SpreadsheetApp.getActiveSheet();
  var dataRange = sheet.getRange(r, 1, 1, 3);

  var data = dataRange.getValues();
  var row = data[0];

  if(row[0] === ""){
    dataRange.setBackgroundRGB(255, 255, 255);
  }else if(row[0] > 0){
    dataRange.setBackgroundRGB(192, 255, 192);
    dataRange.setBackgroundRGB(255, 192, 192);


function onEdit(event)
  var r = event.source.getActiveRange().getRowIndex();
  if (r >= 2) {

function onOpen(){

share|improve this answer
Now updated with example script. – Liam Aug 12 '10 at 10:04
Wow thanks! This is grand! – Robert Koritnik Oct 13 '10 at 16:36
The link to the example is no longer valid. How do you USE this script once it is created? That is missing from this answer. – Daniel Williams Aug 17 '13 at 21:22
There is now a simpler option for the most common use-cases, described in my answer below. – Sam Brightman Dec 24 '13 at 10:09
Google Spreadsheet link is broken unfortunately. Would be nice to have a short description on how to use/activate scripts. Nevertheless great answer that just works. :) – brimborium Feb 25 '14 at 9:13

The new Google Sheets allows you to do this, as described here. You have to first enable the new spreadsheets in your Google Driver settings as described in the article. Then you can select 'Custom formula is' from the conditional formatting options and enter any formula (do not forget to add the = prefix!). Cell references without $ prefixes are adjusted automatically when applied to ranges as you would expect.

It seems that support for migration from old to new is lacking - it only applies to new sheets and I found that only values could be copied from one to the other. Copying an entire sheet may be an option.

share|improve this answer
Thanks for pointing this out. It really works exactly as I want it to. – Robert Koritnik Dec 24 '13 at 11:14
Custom formula is =A1=1 for Range B1:B7 and formatting of choice should work. – pnuts Jun 17 '14 at 20:55
You could mark it accepted if you think it's a simpler, more direct answer to the question (I do!). – Sam Brightman Sep 9 '14 at 11:38
At this time most of the old spreadsheets were migrated to the new Google Sheets, so the note about support for migration is obsolete. – Rubén Oct 14 '15 at 15:44

I wrote this web app, Color Code+, with Apps-Script, to cover most of the basic conditional formatting needs. Throw in some rules and it'll spit out code that you can then paste in your spreadsheet, under ToolsScript editor.... (Help thread on Google forums.)

share|improve this answer

Conditional formatting - custom formula

range 2:227

= if($i:$i = "Duplicate",True,False)

select the color you want the row to be highlighted.

share|improve this answer

Edit in response to the question's clarification:

In your Google Spreadsheet window, there is a menu Format with the option "Change color with rules". This is as technical as Google Spreadsheet's conditional formatting is. As far as I can tell, there is no way to color one cell based on another's value - Google doesn't let you enter formulas for other cells.

Unless you're putting other data into column B, you could always make all of column B equal column A, and then use the "Change color with rules" option to color all the cells with the value of 1 with like colors - ie, red background and red text when the value is 1, white background and white text when it is not, effectively hiding the value in column B. That will give you the look you want.

In Excel, you can do what you want. Using your data as an example, I conditionally formatted B1 when this formula is true:


and then dragged the formatting down, which highlighted only the cells in B where it's neighbor in column A equaled 1.

Excel can do it, but not google

Original Answer

I'm not sure if you can do this in 2 columns, but I know you can do it in 3:

 A  |  B  |  C
 1  |  f  |  x

In the B column, you can use the IF formula to see whether an x has been placed in the appropriate C column:


The IF formula has 3 parts - the test, the then value, and the else value. In the above example, the formula checks to see if there is an x in the C column. If there is, it enters the value from A1, otherwise it enters a blank. It doesn't matter if the x is upper- or lower-case.

Once you enter this formula at the top of your list, you can use the drag feature to drag the formula down for the rest of your list. With the cell highlighted in blue, move your mouse over the square in the lower right corner until the cursor becomes a crosshair. Then just click and hold while dragging down to copy the formula to the cells below.

share|improve this answer
I think you misunderstood me. The question is about conditional formatting not placing values in cells. – Robert Koritnik Dec 1 '09 at 15:44
At this time this answer is obsolete. See Apply conditional formatting rules - Docs editors help – Rubén Jun 14 '15 at 2:00

When editing conditional formatting, select Custom formula and use the following...

=if(A1 = 1 , true)

Select you colors and your done.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.