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

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:

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$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!

Posted on 11 December 2006 by Leslie
Please leave a Comment! Pings are currently off.

844 Feedbacks on "How to use nested IF statements in Excel with AND, OR, NOT"

Ibaad ul Rehman

“I have to compare 2 dates ( one is current date and other date can either old date/future/current date), Current date will be standard date and then have to apply this query-If difference between 2 dates is: More than 3.5 days passed -show “Red”” in next column
if difference between 2 dates is :1 to 3.5 days passed-show “Orange”
if difference between 2 dates is: 0 to 3.5 days remaining show “blue”
if difference is more than 3.5 days remaining then show “green” in next column.
Thanks in advance

Keith Carroll

Annie: I too wanted basically what you were wanting to be able to calculate commissions. So what I did was I created a formula in a few different cells which then was calculated in another cell to get me the result I want. I want it so that way if it is above a specific amount, then they cap out at that amount, and if it’s less than calculate that amount. If they don’t hit the minimum, then no bonus. So in line with the examples above, I put in the cells next to it, the following; =IF(B6>$B$3,$B$3,0)*$B$1, then in the next cell, =IF(AND(B6>$B$2,B6<$B$3),B6*$B$1,0), and then in the next cell is the final calculation, =IF(SUM(D6:E6)=0,"No Bonus",SUM(D6:E6)). This makes it a little longer, but as I was trying to put it all in one formula, I kept getting errors, so I split it up and then hid the cells that had the calculations.

For your direct questions though, I would do the following next to the cells in question, =SUM(C6:F6) to show the sum, =IF(A6$A$1,A6$A$2,A6$A$3,$B$4,0) to calculate greater than. This is a little more drawn out, but it works and gets the job done without any errors, or banging of the noggin.

Keith Carroll

Sarthak Singla, the lookup function should be used when you are trying to look up a specific value for a specific item, as in; if I want the price of a specific product in A1, it would be pull the product up (preferably from a drop down menu to enable proper spelling), then the item number and so on, not when trying to calculate items between a specific number.

S Sealy

Hi I am trying to write an IF formula to calculate residential water rates using the following rate blocs:
$2.48 per m3 (0-8 m3);
$3.10 per m3 (9-20 m3);
$4.66 per m3 (21-40 m3) and
$7.78 per m3 (over 40 m3)
but I am not getting it worked out. Can you please help me. Thanks.

A Thangaraj

TANGIRALA SRINIVAS

In Excel under the head “LOCATION” there are 3 cities namely ‘X’, ‘Y’ and ‘Z’

The % age of HRA under the head “HOUSE RENT ALLOWANCE” is assigned to the cities are ‘X’=30%, ‘Y’=20% and ‘Z’=10% respectively.

I wish to put a condition in the cell under the head “HOUSE RENT ALLOWANCE” that if the location is ‘X’, it should return the value 30%, If ‘Y’, it should return the value 20% and if ‘Z’ it should return 10%

Please help me to insert appropriate function in the cell, to result the desired value

neville

dear sir
I have a problem in excel
I want to calculate the with excel formula for the following problem
I have a amount of say $ 600,000 upto 400,000 the charge is 0.25% above 400,000 it is 0.125% how can I solve the same using if formula

Mahwish

dear sir
I have a problem in excel
I want to calculate the with excel formula for the following problem there are some grades and foliwng % of bonus amount how 2 criteria match ? using which farmoula to evaluate result
like on if grade is A1 and rating is “B” amount will be 1 salary and if grade will be c3 and rating is “S” amount will be 2 salary
B1+ includes below
23
22
21
20
13
12
11
10
A4
A3
A2
A1
B4
B3
B2
B1

Sam

I am trying to do the following. Cell B2 is “male” or “female”. There is a calculation that gives me a number in cell B5. If B5 is >0.95 for Males, then I want “High”. If less than 0.95, I want “low”. For females the threshold for “high” or “low” is 0.80. I want to be able to put either “male” or “female” in B2 and then have excel know which “If” statement to pull. I have tried a few iterations and have not had luck. Thanks

I am leaving a comment here because of what I am trying to do which is this.

Let me use this example, I have a bible that is in excel format. If one, wanted to search a particular word or phrase in the bible, they can simply use the find command within excel to produce their result.

Now my question is this, I want to do the opposite of that. I am thinking I have to use If statements to create the table I am wanting to put together.

For example, I would like to look at a table that shows me every word that is listed in the bible only six times, and/or any phrase /or phrases that are only together six times in the bible.

Yvonne

After Greetings
Your assistance will be appreciated in developing a sales incentives formula where it will calculate price list based on total volumes of product.

Examples:
1- If the total monthly volume falls between 450-549, no sales incentive applied.
2- If the total monthly volume falls between 350-449, 1% penalty will be added on the cost price.
3- if the total monthly volume falls between 550-649, 1% bonus will be reduced from the cost price
4- If the total monthly sale exceeds 1000, 4% bonus will be reduced from the cost price.
Your assistance will be highly appreciated.
Alialiuae69@gmail.com

Brian

I need some help on a complicated string. I need multiple if’s because I want to make a string that will reflect a person’s name depending on 2 true functions.

So far for a single function it works:
=IF(AND(I2=”ABC”,J2=”First”),”James”)

but if I want to add a continuation of
=IF(AND(I2=”ABC”,J2=”First”),”James”),IF(AND(I2=”ABC”,J2=”Second”),”Max))
This does not work.

Basically I want this cell to reflect:
IF I2=ABC and J2=First, James.
IF I2=ABC and J2=Second, Max

Also please advise on a continuation after if I need to add more strings.
For instance:
IF I2=ABC and J2=First, James.
IF I2=ABC and J2=Second, Max
IF I2=CAB and J2=First, Brian
IF I2=CAB and J2=Second, Alex
IF I2=ACB and J2=First, Charles
IF I2=ACB and J2=Second, Rango

Anna

=IFERROR(IF(OR(WEEKDAY(B12;2)>6;(O12>P12));(O12-P12)*(1+F12);IF(OR(MATCH(B12;Holidays;0);(O12>P12));(O12-P12)*(1+F12);IF(OR(WEEKDAY(B12;2)>6;(O12<P12));(P12-O12)*(1+F12);IF(OR(MATCH(B12;Holidays;0);(O12<P12));(P12-O12)*(1+F12)))));0)
This doesnt work (trying to caclulate hours)