***************

Following up on last week’s introductory post on using the IF function, here’s one on how to use Excel’s IF statement when you have multiple conditions to meet.

The original question I received from a reader, which prompted this series, was about how to use the IF statement in Excel when you had two conditions that had to be met. For example, when sales fell between a minimum and maximum number. Let’s take a look at our example again. Note that I’ve added the maximum amount of $200K into cell B3:

Before we go further, if you’d like to work through the examples yourself, here’s the raw data you can copy into an Excel worksheet. First, open up a blank excel worksheet. Next, highlight the table below. Copy it, and then go back to your excel worksheet. Go to cell A1 (or another empty cell, if you want to put the data elsewhere), and then select “Edit” from the menu bar. Select “Paste Special” and then “Text” from the popup box. Click “OK”. The data should appear in your Excel worksheet just as it does above.

Bonus | 12% | |

Minimum amount | 100000 | |

Maximum amount | 200000 | |

Sales | Bonus | |

Salesman A | 87925 | |

Salesman B | 100000 | |

Salesman C | 145000 | |

Salesman D | 200750 | |

Salesman E | 178650 | |

Salesman F | 99555 | |

Salesman G | 147000 | |

Salesman H | 213450 | |

Salesman I | 122680 | |

Salesman J | 92500 |

Ok, now back to the tutorial.

Now, let’s suppose sales have to be greater than or equal to $100K **and** less than $200K for a salesman to receive a 12% commission rather than just be greater than $100K, as in our introductory example. How would you write that in “Excel-speak”?

It turns out that you can use Excel’s AND function, which Excel calls a logical operator (just like it calls the IF function). And, as usual, unlike how most other programming languages work, the syntax required in Excel is a bit different. To use it correctly, you have to write it like the following:

**=AND(first condition, second condition, …, etc.)**

(In other programming languages, AND would fall in between each condition, just like how we normally talk, but not in Excel!)

Let’s go back to the concrete example. To write the condition that sales have to fall betwen $100K and $200K for the salesman to receive a 12% commission, we’d write the following in cell C6:

**=IF(AND(B6>=$B$2, B6<$B$3),B6*$B$1,"No bonus")**

Like this:

Translated into plain English, our IF statement now reads, “If B6 is greater than or equal to B2 **and** B6 is less than B3, then multiply B6 by B1. If not, then put ‘No bonus’ into the cell.” In the first case, our salesman didn’t meet the $100K requirement, so the AND function returned a false, so the IF statement put “No bonus” into the cell. By the way, in our case, we only had two conditions to meet, but if we had more, we could just keep adding them into the list of conditions in the parenthese after the AND function.

Here’s how the results look if we do this for all the salesmen in our example:

There are two other logical functions, OR and NOT, which work the exact same way:

**=OR(first condition, second condition, …, etc.)**

**=NOT(first condition, second condition, …, etc.)**

For example, we could actually rewrite our IF statement above using the OR condition if we’re careful. Here’s how it would look:

**=IF(OR(B6<$B$2,B6>=$B$3),”No bonus”, B6*$B$1)**

Like this:

Again, in plain English, what we’re saying is, “If B6 is less than B2 **or** B6 is greater than or equal to B3, put ‘No bonus’ into the cell. Otherwise, multiply B6 by B1.” We’re basically testing for the opposite conditions in our OR statement as we did in our AND statement. And you’ll get the same results as above with the AND statement, as seen below:

You might be able to picture now how you could start using multiple AND, OR, and IF statements nested altogether to test all sorts of complicated conditions in Excel. But keep in mind that cells in Excel are really meant more for doing calculations than programming, which is really what you’re getting into once you start putting in complex IF statements. (I’ve read somewhere you can nest up to 7 IF statements in Excel, though I’m not sure to which version(s) of Excel that limitation applies.)

In particular, coming up with a correct list of conditions to test for, in the right order, that don’t result in a false positive test (e.g. a condition accidentally being met that you didn’t mean to) is a big concern in Excel. The other problem is usability. Even if you were able to come up with a complex IF statement that did what you wanted it to, imagine you put the spreadsheet away and revisited it again in a year’s time when you had to update annual sales figures and calculate bonuses again. Here’s an example of a complicated nested IF statement with no other logical operators:

**=IF(A1<20, A1*1, IF(A1<50, A1*2, IF(A1<100, A1*3, A1*4)))**

Think about it: would you *really* want to spend an extra hour or two decoding that and figure out what you needed to change or update a year later? Similarly, if you had to use a worksheet that someone else wrote that contained a bunch of complicated IF statements, wouldn’t you go nuts? I would!

The statement above is actually even in “reverse” order of what you might normally expect. (In case you’re wondering, I pulled this example from the bottom of a webpage here. It provides the original reader’s question, though why he or she wanted to calculate that, I’m not sure!)

I’ll follow up this post with one on conditional formatting, and I’ve had a request to explain VLOOKUP, HLOOKUP, and pivot tables. Feel free to suggest other tutorials you’d like to see, and I’ll try my best to get to them!

***************************************************

**Look Good at Work and Become Indispensable Become an Excel Pro and Impress Your Boss**

***************************************************

## AP

Hello!

I am trying to right a nested IF statement and no luck. Each of the below statements works individually, but when I try using them together I am getting the #Value error. Any help would be greatly appreciated!

=IF(AND(R4=Q4,T4=S4), “Match”, “No Match”),IF(AND(T4=S4,R4Q4),”Campaign No Match”,””),IF(AND(R4=Q4,T4S4),”Adgroup No Match”,””)

Context:

If values columns R and Q match as well as values in columns T and S, then the value should show “Match”

If values in columns T and S match, but values in columns R and Q do NOT match then the value should show “Campaign No Match”

If values in columns R and Q do match, but values in T and S do NOT match then the value should show “Adgroup No match”

thanks in advance

## ASLINAH

A B C

12345 10

12345 20

12345 LTP 30

12346 25

12346 30

12346 LTP 24

how to make formula if column A have same value, take column B “LTP” . The answer should return for 12345 ,30 & 12346 , 24

## Kane

To AP:

=IF(AND(Q4=R4,S4=T4),”Match”,IF(AND(S4=T4,NOT(Q4=R4)),”Campaign No Match”,IF(AND(Q4=R4,NOT(S4=T4)),”Adgroup No match”,””)))

Being ‘nested’ each subsequent logical needs to be contained within the [value_if_false] parameter of the if statements – the ,”” at the end says that if none of the statements are true, return nothing.

Hope it helps!

## ravi

Hello all,

Is below formula correct?

=IF(L4= “1650”, “XM3”, “XM2”, IF(L4= “1602”, “XM3”, “XM2”, IF(L4= “1674”, “XM2”, “XM3”, IF(L4= “Alpha Model DM3X”, “XM2”, “XM3”))))

I am getting an error, so many arguments.

Kindly help.

## Laxman Poyrekar

X Column Male Y Column >=1.5% “Yes”,”No”, X Column Female Y Column >=2% “Yes”,”No”

Please send formula

## Laxman Poyrekar

help on urgent basis

## Catero

I am trying to do 3 (IF(OR in 1 statement but keep getting #VALUE or FALSE returned. I’m tearing my hair out – I hope someone can help me

This returns FALSE:

=IF(OR(B2=”Kitchen and Bathroom”,B2=”Bathroom and WC Only”),”KIT014″,”NO DATA”) =IF(OR(B2=”Bathroom Only”,B2=”Kitchen and WC Only”),”BAT009″,”NO DATA”) =IF(OR(B2=”WC Only”,B2=”Kitchen Only”),”KIT031″,”NO DATA”)

And this returns #VALUE:

=IF(OR(B5=”Kitchen and Bathroom”,B5=”Bathroom and WC Only”),”KIT014″,”NO DATA”), IF(OR(B5=”Bathroom Only”,B5=”Kitchen and WC Only”),”BAT009″,”NO DATA”), IF(OR(B5=”WC Only”,B5=”Kitchen Only”),”KIT032″,”NO DATA”)

## Marie

Hi, It seems you are good at ecxel.

I need your help and I really hope you can help med.

I need to make a IF(AND( function but I have 13 intervals which exceed the limit for nesting.

This is the criteria

5<=A1<=9 then its 3000

10<=A1<=19 then its 5000 and so on.

How do I do this as a function when I cant use IF(AND because it only allow 7 intervals.

Please help med!

Best Regards

Marie

## Rob

I have the same problem as Marie. Any assistance would help?

## Please Leave a Comment!