# How to include multiple IF statements in one cell in Google sheets

I am attempting to change the value of a cell in Google Sheets based on the value of an adjacent cell. This adjacent cell gets its value from the colour of the cell adjacent to it using the formula from this Quora answer. So the value of the cell should change based on the hex code which is obtained from the colour of the first cell. There are 4 possible hex values at the moment so I was trying to put 4 different if statements in the same cell so its value is changed based on this.

My first attempt led to a formula parse error:

``````=if((J2="#00ff00","Read"), if(j2="#ff0000", "Unread"), if(j2="#ff9900","In Progress"), if(j2="#000000", "Not Applicable"))
``````

It is clear you cannot simply separate if statements with commas. Based on this stack overflow question I tried this code, with nested if statements:

``````=if((J2="#00ff00","Read", if(j2="#ff0000", "Unread", if(j2="#ff9900","In Progress",if(j2="#000000", "Not Applicable")))))
``````

This also leads to a formula parse error.

Is there any way I can simply include multiple if statements in the same cell which will work for my code?

Note: Thanks for any help, I am happy to test any code and answer further questions. Please edit if necessary.

-
Can you combine them into an =OR or something similar? – AccioBooks Jan 23 at 14:53

Use `lookup` instead of `if`:

``````=lookup(B7,
{"#000000","#00ff00","#ff0000","#ff9900"},
)
``````

Note the second parameter must be a sorted list.

-
Thank you very much, this works perfectly! – Jack Graveney Jan 23 at 17:59

The problem in the examples provided are the parenthesis. Apply them properly.

# Explanation

`IF()` function should have two parameters and optionally a third one.

``````IF(logical_expression, value_if_true, value_if_false)
``````

The specific problem with

• the first example provided is that the outer `IF()` has too many parameters.
• the second example is that the logical_expression of the outer `IF()` do not return `TRUE` or `FALSE`

In Google Sheets functions the parameters are separated by commas. When parenthesis are used to enclose several operations and functions inside a function they are considered as a parameter of the function that contains them.

A common practice is to put the inner IF() as the `value_if_false`, but it could be done in many ways. Adding IF() inside another other as `value_if_true` and `value_if_false` is called `IF() logical test nesting` or just `IF() nesting`.

Below is an example of a formula that have having three `IF()`, two of them used to determine the `value_if_false` of the parent `IF()`. A multi-line and vertical align of parenthesis style is applied for readability

`````` =IF(logical_expression, value_if_true,
IF(logical_expression, value_if_true,
IF(logical_expression, value_if_true, value_if_false
)
)
)
``````

The above style could be used in Google Sheets formula writing. I found it useful for formula debugging.

# Reference

-

You can nest IF statements for example

``````If(if(if(when all 3 equal true)))
``````

Would work

OR

you could use a nested IFAND for example

``````IF(AND(AND()))
``````

Would also work.

-
The IF() function requires at least two parameters. See webapps.stackexchange.com/a/89068/88163 – Rubén Jan 25 at 15:29