In this article, you will learn how to build an Excel IF statement for different types of values as well as how to create multiple IF statements.
IF is one of the most popular and useful functions in Excel. Generally, you use an IF statement to test a condition and to return one value if the condition is met, and another value if the condition is not met.
In this tutorial, we are going to learn the syntax and common usages of the Excel IF function, and then take a closer look at formula examples that will hopefully prove helpful to both beginners and experienced users.
IF function in Excel
IF is one of logical functions that evaluates a certain condition and returns one value if the condition is TRUE, and another value if the condition is FALSE.
The syntax of the IF function is as follows:
As you see, IF takes a total of 3 arguments, but only the first one is obligatory, the other two are optional.
Logical_test (required) - the condition to test. Can be evaluated as either TRUE or FALSE.
Value_if_true (optional) - the value to return when the logical test evaluates to TRUE, i.e. the condition is met. If omitted, the value_if_false argument must be defined.
Value_if_false (optional) - the value to return when the logical test evaluates to FALSE, i.e. the condition is not met. If omitted, the value_if_true argument must be set.
Basic IF formula in Excel
To create a simple If then statement in Excel, this is what you need to do:
- For logical_test, write an expression that returns either TRUE or FALSE. For this, you'd normally use one of the logical operators.
- For value_if_true, specify what to return when the logical test evaluates to TRUE.
- For value_if_false, specify what to return when the logical test evaluates to FALSE. Though this argument is optional, we recommend always configuring it to avoid unexpected results. For the detailed explanation, please see Excel IF: things to know.
As an example, let's write a very simple IF formula that checks a value in cell A2 and returns "Good" if the value is greater than 80, "Bad" otherwise:
=IF(B2>80, "Good", "Bad")
This formula goes to C2, and then is copied down through C7:
In case you wish to return a value only when the condition is met (or not met), otherwise - nothing, then use an empty string ("") for the "undefined" argument. For example:
=IF(B2>80, "Good", "")
This formula will return "Good" if the value in A2 is greater than 80, a blank cell otherwise:
Excel If then formula: things to know
Though the last two parameters of the IF function are optional, your formula may produce unexpected results if you don't know the underlying logic.
If value_if_true is omitted
If the 2nd argument of your Excel IF formula is omitted (i.e. there are two consecutive commas after the logical test), you'll get zero (0) when the condition is met, which makes no sense in most cases. Here is an example of such a formula:
=IF(B2>80, , "Bad")
To return a blank cell instead, supply an empty string ("") for the second parameter, like this:
=IF(B2>80, "", "Bad")
The screenshot below demonstrates the difference:
If value_if_false is omitted
Omitting the 3rd parameter of IF will produce the following results when the logical test evaluates to FALSE.
If there is just a closing bracket after value_if_true, the IF function will return the logical value FALSE. Quite unexpected, isn't it? Here is an example of such a formula:
=IF(B2>80, "Good")
Typing a comma after the value_if_true argument will force Excel to return 0, which doesn't make much sense either:
=IF(B2>80, "Good",)
The most reasonable approach is using a zero-length string ("") to get a blank cell when the condition is not met:
=IF(B2>80, "Good", "")
Tip. To return a logical value when the specified condition is met or not met, supply TRUE for value_if_true and FALSE for value_if_false. For the results to be Boolean values that other Excel functions can recognize, don't enclose TRUE and FALSE in double quotes as this will turn them into normal text values.
Using IF function in Excel - formula examples
Now that you are familiar with the IF function's syntax, let's look at some formula examples and learn how to use If then statements in real-life scenarios.
Excel IF function with numbers
To build an IF statement for numbers, use logical operators such as:
- Equal to (=)
- Not equal to (<>)
- Greater than (>)
- Greater than or equal to (>=)
- Less than (<)
- Less than or equal to (<=)
Above, you have already seen an example of such a formula that checks if a number is greater than a given number.
And here's a formula that checks if a cell contains a negative number:
=IF(B2<0, "Invalid", "")
For negative numbers (which are less than 0), the formula returns "Invalid"; for zeros and positive numbers - a blank cell.
Excel IF function with text
Commonly, you write an IF statement for text values using either "equal to" or "not equal to" operator.
For example, the following formula checks the Delivery Status in B2 to determine whether an action is required or not:
=IF(B2="delivered", "No", "Yes")
Translated into plain English, the formula says: return "No" if B2 is equal to "delivered", "Yes" otherwise.
Another way to achieve the same result is to use the "not equal to" operator and swap the value_if_true and value_if_false values:
=IF(C2<>"delivered", "Yes", "No")
Notes:
- When using text values for IF's parameters, remember to always enclose them in double quotes.
- Like most other Excel functions, IF is case-insensitive by default. In the above example, it does not differentiate between "delivered", "Delivered", and "DELIVERED".
Case-sensitive IF statement for text values
To treat uppercase and lowercase letters as different characters, use IF in combination with the case-sensitive EXACT function.
For example, to return "No" only when B2 contains "DELIVERED" (the uppercase), you'd use this formula:
=IF(EXACT(B2,"DELIVERED"), "No", "Yes")
If cell contains partial text
In situation when you want to base the condition on partial match rather than exact match, an immediate solution that comes to mind is using wildcards in the logical test. However, this simple and obvious approach won't work. Many functions accept wildcards, but regrettably IF is not one of them.
A working solution is to use IF in combination with ISNUMBER and SEARCH (case-insensitive) or FIND (case-sensitive).
For example, in case "No" action is required both for "Delivered" and "Out for delivery" items, the following formula will work a treat:
=IF(ISNUMBER(SEARCH("deliv", B2)), "No", "Yes")
For more information, please see:
Excel IF statement with dates
At first sight, it may seem that IF formulas for dates are akin to IF statements for numeric and text values. Regrettably, it is not so. Unlike many other functions, IF does recognize dates in logical tests and interprets them as mere text strings. In other words, you cannot supply a date in the form of "1/1/2020" or ">1/1/2020". To make the IF function recognize a date, you need to wrap it in the DATEVALUE function.
For example, here's how you can check if a given date is greater than another date:
=IF(B2>DATEVALUE("7/18/2022"), "Coming soon", "Completed")
This formula evaluates the dates in column B and returns "Coming soon" if a game is scheduled for 18-Jul-2022 or later, "Completed" for a prior date.
Of course, there is nothing that would prevent you from entering the target date in a predefined cell (say E2) and referring to that cell. Just remember to lock the cell address with the $ sign to make it an absolute reference. For instance:
=IF(B2>$E$2, "Coming soon", "Completed")
To compare a date with the current date, use the TODAY() function. For example:
=IF(B2>TODAY(), "Coming soon", "Completed")
Excel IF statement for blanks and non-blanks
If you are looking to somehow mark your data based on a certain cell(s) being empty or not empty, you can either:
- Use the IF function together with ISBLANK, or
- Use the logical expressions ="" (equal to blank) or <>"" (not equal to blank).
The table below explains the difference between these two approaches with formula examples.
Logical test | Description | Formula Example | |
Blank cells | ="" |
Evaluates to TRUE if a cell is visually empty, even if it contains a zero-length string. Otherwise, evaluates to FALSE. |
=IF(A1="", 0, 1)
Returns 0 if A1 is visually blank. Otherwise returns 1. If A1 contains an empty string (""), the formula returns 0. |
ISBLANK() |
Evaluates to TRUE is a cell contains absolutely nothing - no formula, no spaces, no empty strings. Otherwise, evaluates to FALSE. |
=IF( Returns 0 if A1 is absolutely empty, 1 otherwise. If A1 contains an empty string (""), the formula returns 1. |
|
Non-blank cells | <>"" | Evaluates to TRUE if a cell contains some data. Otherwise, evaluates to FALSE.
Cells with zero-length strings are considered blank. |
=IF( Returns 1 if A1 is non-blank; 0 otherwise. If A1 contains an empty string, the formula returns 0. |
ISBLANK() |
Evaluates to TRUE if a cell is not empty. Otherwise, evaluates to FALSE.
Cells with zero-length strings are considered non-blank. |
=IF( Works the same as the above formula, but returns 1 if A1 contains an empty string. |
And now, let's see blank and non-blank IF statements in action. Suppose you have a date in column B only if a game has already been played. To label the completed games, use one of these formulas:
=IF(B2="", "", "Completed")
=IF(ISBLANK(B2), "", "Completed")
=IF($B2<>"", "Completed", "")
=IF(ISBLANK($B2)=FALSE, "Completed", "")
In case the tested cells have no zero-length strings, all the formulas will return exactly the same results:
Check if two cells are the same
To create a formula that checks if two cells match, compare the cells by using the equals sign (=) in the logical test of IF. For example:
=IF(B2=C2, "Same score", "")
To check if the two cells contain same text including the letter case, make your IF formula case-sensitive with the help of the EXACT function.
For instance, to compare the passwords in A2 and B2, and returns "Match" if the two strings are exactly the same, "Do not match" otherwise, the formula is:
=IF(EXACT(A2, B2), "Match", "Don't match")
IF then formula to run another formula
In all of the previous examples, an Excel IF statement returned values. But it can also perform a certain calculation or execute another formula when a specific condition is met or not met. For this, embed another function or arithmetic expression in the value_if_true and/or value_if_false arguments.
For example, if B2 is greater than 80, we'll have it multiplied by 7%, otherwise by 3%:
=IF(B2>80, B2*7%, B2*3%)
Multiple IF statements in Excel
In essence, there are two ways to write multiple IF statements in Excel:
- Nesting several IF functions one into another
- Using the AND or OR function in the logical test
Nested IF statement
Nested IF functions let you place multiple IF statements in the same cell, i.e. test multiple conditions within one formula and return different values depending on the results of those tests.
Assume your goal is to assign different bonuses based on the score:
- Over 90 - 10%
- 90 to 81 - 7%
- 80 to 70 - 5%
- Less than 70 - 3%
To accomplish the task, you write 3 separate IF functions and nest them one into another like this:
=IF(B2>90, 10%, IF(B2>=81, 7%, IF(B2>=70, 5%, 3%)))
For more formula examples, please see:
Excel IF statement with multiple conditions
To evaluate several conditions with the AND or OR logic, embed the corresponding function in the logical test:
For example, to return "Pass" if both scores in B2 and C2 are higher than 80, the formula is:
=IF(AND(B2>80, C2>80), "Pass", "Fail")
To get "Pass" if either score is higher than 80, the formula is:
=IF(OR(B2>80, C2>80), "Pass", "Fail")
For full details, please visit:
If error in Excel
Starting from Excel 2007, we have a special function, named IFERROR, to check formulas for errors. In Excel 2013 and higher, there is also the IFNA function to handle #N/A errors.
And still, there may be some circumstances when using the IF function together with ISERROR or ISNA is a better solution. Basically, IF ISERROR is the formula to use when you want to return something if error and something else if no error. The IFERROR function is unable to do that as it always returns the result of the main formula if it isn't an error.
For example, to compare each score in column B against the top 3 scores in E2:E4, and return "Yes" if a match is found, "No" otherwise, you enter this formula in C2, and then copy it down through C7:
=IF(ISERROR(MATCH(B2, $E$2:$E$4, 0)), "No", "Yes" )
For more information, please see IF ISERROR formula in Excel.
Hopefully, our examples have helped you get a grasp of the Excel IF basics. I thank you for reading and hope to see you on our blog next week!
Practice workbook
Excel IF statement - formula examples (.xlsx file)
4804 comments
I need help with a formula using dates:
What I am trying to accomplish is if cell G2< 7/1/14 then insert 7/1/14 but if not insert the date that is in G2.
=IF(G2<DATEVALUE("7/1/2014"),"7/1/2014",G2)
Thanks for any help,
Hi Monica,
Your formula is correct. If it returns a serial number rather than a date, you should simply apply the Date format to the cell (press Ctrl+1 to open the Format Cell dialog and select the Date format you want).
Can you help me with this formula:
=IF(AND(AE303="",AK303=""),Incident),IF(AND(AE303""),AK303="",(NOW()-(AE303))),(DATEDIF(AE303,AK303,"D")))
I am trying to have the formula:
(1) if cell AE303 and AK303 are both blank put in the word "Incident", but
(2) if cell AE303 has a date in the cell and AK303 is blank insert number of days between AE303 and Today, but
(3)if both cells have dates, subtract them and tell me the # of days between
Hi Lana,
Try this formula:
=IF(AND(AE303="",AK303=""), "Incident", IF(AND(AE303<>"",AK303=""), TODAY()-AE303, IF(AND(AE303<>"", AK303<>""), DATEDIF(AE303,AK303,"D"))))
Just keep in mind please that DATEDIF requires the start date (AE303) to be always less than the end date (AK303), otherwise a formula will return the NUM! error. An easy workaround is simply subtracting one date from the other in the last value_if_false argument:
AK303-AE303
I'm attempting a similar formula as step (2) noted in Lana's question but I cannot get it to work.
The sheet has set due dates for a task to be done. There is a column for the completed date (C) and the days overdue (D) based on the due date.
I'm trying to get the number of days overdue to show in column D (due date is in C2) if there is not a completed date in C, otherwise if there is a date in C, I'd like the cell to stay blank.
Tried this formula, but it shows as FALSE when there is a date in C instead of coming up blank:
=IF(AND(C5=""), TODAY()-$C$2)
[Row 5 is the first row of data excluding the due date in row 2, so I'm intending on dragging down the remaining rows]
Hopefully you can help me with this!
Hi!
I’m not sure I got you right since the description you provided is not entirely clear. However, it seems to me that the formula below will work for you:
=IF(C5="", TODAY()-$C$2,"")
i need a formula to display a number (2) if the cell says "yes" and display a (4) if the cell says "no"....
can anyone help?
Here you go:
=IF(A1="yes", 2, IF(A1="no", 4, ""))
i cannot figure the formula out help!!!
In cell F20, enter an IF function that tests whether the order quantity in cell E20 is greater than zero. If it is, return the the charge for this item, which is the value of cell E20 mulitplied by cell D20. Otherwise, return a space by entering " " (that is, double quote, space, double quote). Autofill this formula into the range F21:F25.
Hi Ana,
Here's the formula for F20:
=IF($E20>0, $E20*$D20, " ")
Simply copy it down to other cells in column F:
- select cell F20;
- move the mouse cursor at the lower right-hand corner of the cell and you will see it changing to a plus sign (fill handle);
- click the plus and drag it down to fill other cells with your formula.
I have a tricky question...I want sheet 2 to return an if statement that calculates on sheet 1.: =if(MaterialBreakdown[SARA Title 313}="*YES", MaterialBreakdown[Material Name], NA. That is the formula I tried to use, but it gave me an error. I want all materials in column A to list in another sheet if they have yes in column C. I am really bad at explaining this!
all help appreciated!
I NEED YOUR HELP IN THIS FORMULA:
=IF(K26="CHEMICAL TANKER",IF(AND(K26>=0,K26=5000,K26=10000,K2620000,550))))),IF(K26="GENERAL CARGO",IF(AND(K26>=0,K26=5000,K2610000,490))))
THE ANSWER IS= #VALUE
IS THERE ANY POSSIBILITY TO COMBINE MORE THAN ONE IF STATEMENT IN ONE CELL?
I WANT TO ADD OTHER IF CONDITIONS IE,"BULK","CARGO" AND SO ON.
IS THERE ANY LIMITATION FOR THIS CONDITION? TQ
What if I want to say if cells F1, G1, and H1 are blank, I1 should be blank. If F1, G1 and H1 have numbers, then I1 should be F1+G1+H1.
Hi James,
Should I1 be blank if any of cells F1, G1, and H1 is blank or if all 3 cells are blank?
And what if any of those cells contains a text value?
Hi,
I have two membership type groups; member and non-member (column A). I have registration start dates (column B) and registration end dates (column C). I need to confirm that the start and end dates for registration fall within the acceptable date range for both members and non-members. Members range (6/1/15 – 8/31/15); Non-Members (6/8/15 – 8/31/15).
Thanks!
Hi Guys, how are you?
I imported data from TXT file when the field BDATE came like below:
09/09/2013
09/09/2013
09/09/2013
09/09/2013
30/12/2011
14/03/2013
24/09/2013
24/09/2013
30/12/2011
This format is British style (DD/MM/YYYY), when I convert to American style (MM-DD-YYYY) the date that begin > 12 were not converted.
Somebody knows what to do?
Thanks!
Hi
Need to insert if formula where there are four dates (one in each column) and need a yes answer if any of the dates are greater than one date but less than another date. eg. if any of the four dates were greater than 01/06/15 but less than 30/06/15 I need the answer to be yes
Thanks. LP
Lindsay,
Please use this formula:DATEVALUE("01/06/15")), AND(A2DATEVALUE("01/06/15")), AND(A3DATEVALUE("01/06/15")), AND(A4DATEVALUE("01/06/15"))), "Yes","")
=IF(OR(AND(A1
Where A1, A2, A3, A4 are cells with the dates.
Hi Svetlana,
What is the formula to highlight non-date cell on particular future dates?
e.g.
A1 cell contains Name and I want to highlight this name between 20 May 2015 to 22 May 2015.
Can you please, help me with the formula for this?
Regards,
Sid.
How to set if condition for following:
=ROUND(VLOOKUP(G6,'2012 IAM Table raw'!A$2:D$122,4,FALSE)*((1-VLOOKUP(G6,'2012 IAM Table raw'!A$2:E$122,5,FALSE))^F6),3)/1000
this round value will return some value, if values is not return need to set the field value to 0 (zero)
Hi Harish,
You can try to wrap your VLOOKUP function with IFERROR like this:
=ROUND(iferror(VLOOKUP(G6,'2012 IAM Table raw'!A$2:D$122,4,FALSE) * ((1-VLOOKUP(G6,'2012 IAM Table raw'!A$2:E$122,5,FALSE))^F6), 0), 3)/1000
Dear Svetlana,
I tried =TEXT(O2,"dd-mmmm-yy") and which (O2)=IF(B2="delivered", TODAY(), "")
it workeed yesterday and (cell P2) shown 12-May-15 but it updated to 13-May-15 today morning.
So how to lock the date(cell P2) at 12-May-15?
thank you.
Hi Zhao,
Regrettably, it's not possible to lock the date using formulas. You either have to replace the formula with its value each time manually (Copy > Paste Special > Value) or write a VBA script that automates this.
For some reason, every time I submit my question, it cuts down on how I originally wrote my formula.
=IF(AND(A1>=1,A1=5,A1<10),5,10))
This will only return the number 10.
Hi Eric,
Our blog engine often mangles formulas in comments, sorry for this. Could you please describe your conditions in words, so that I can understand the logic? So, the formula should return:
5 if ?
10 if?
1 if?
Hi, I am trying to write a formula that pulls in a number of 1, 5 or 10. The numbers in cell A1 range anywhere from 1 - 25. I presently have it set up as follows:
=IF(AND(A1>=1,A1=5,A1<10),5,10))
The formula takes, but it only returns the number 10 in all instances. Help!!
Hi, I am trying to write a formula that pulls in a number of 1, 5 or 10. The numbers in cell A1 range anywhere from 1 - 25. I presently have it set up as follows:
=IF(AND(A1>=1,A1=5,A1<10),5,10))
The formula takes, but it always returns the number 10 in every instance. Can't figure this out. Hoping you can help.
Hi, working on an excel spreadsheet for invoices.
Column A is quantity, b & c are description, D is unit price and E total
I need a formula that calculates A*D in column E but remains blank when column A is blank
Thank you
Hi Fitz,
Try the following formula:
=IF(A2<>"", A2*D2, "")
awesome. perfect. thank you Svetlana
if the same way I want to get "Yes" if value greater than A1, else remain blank. Also if there is no value in A1 still remains blank
=IF(B2="delivered", TODAY(), "")
I use this formula to generate delivery date, but i found that the date will updated to the date of next day... So how to maintain the date there for me to check the delivery date few days later? thanks.
hi..
i have just got answer from your previous post that
"How to convert date to text using Excel TEXT function and no-formula ways"
...ha, it`s helpful, thank you very much, but i am not sure whether it will be updated tomorrow
=IF(CV2<=28,"Poor", IF(28<CV2<=42,"Borderline","Acceptable"))
I wrote the formula above but it's only selecting "Poor" and "Acceptable", leaving out "Borderline" Any help?
Hi Phil,
Regrettably IF cannot understand expressions like 28<CV2<=42. You have to use an AND statement is this case:
=IF(CV2<=28,"Poor", IF(AND(CV2>28, CV2<=42),"Borderline","Acceptable"))
But in fact, checking for CV2>28 is superfluous and you can put it simply as:
=IF(CV2<=28,"Poor", IF(CV2<=42,"Borderline","Acceptable"))
Friends I want to a formula who auto calculate with given material with its value.
Ex.
If Material is Sand and its value 41....its divided by its net weight(12000)
I want to just type different Materials Name like sand and its auto divided with weight.