How to use IF function in Excel: examples for text, numbers, dates, blanks

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:

IF(logical_test, [value_if_true], [value_if_false])

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: Basic IF formula in Excel.

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: IF formula to return nothing when the condition is not met.

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: The behavior of the value_if_true argument.

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", "") The behavior of the value_if_false argument.

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. A formula to check if a cell contains a negative number.

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. Using the IF function with text.

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") Case-sensitive IF statement for text values.

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") IF cell contains partial text.

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. Excel IF statement with dates.

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(ISBLANK(A1), 0, 1)

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(A1<>"", 1, 0)

Returns 1 if A1 is non-blank; 0 otherwise.

If A1 contains an empty string, the formula returns 0.

ISBLANK()=FALSE Evaluates to TRUE if a cell is not empty. Otherwise, evaluates to FALSE.

Cells with zero-length strings are considered non-blank.

=IF(ISBLANK(A1)=FALSE, 0, 1)

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: IF statement for blank and non-blank cells.

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", "") Check if two cells contain the same values.

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") Case-sensitive IF formula to check if two cells 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%) IF formula that runs another formula.

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%))) Nested IF statement.

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") Excel IF statement with multiple conditions.

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" ) If error formula in Excel.

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

  1. Dear Svetlana,

    I would like requesting help from you, I need in excel Coulmn A2 to A100 each coulmn having different numbers and I need to display in B2 column "More Line" if A2 to A100 coulmn's any numbers greater than 3.

    Lines
    1
    1
    1
    1
    1
    2
    2
    2
    3
    3

    • Hi Abdul,

      Try the following formula:
      =IF(MAX(A2:A100)>3, "more line", "")

  2. Hi Svetlana
    A2, A3, A4 and A5 cells have the following info
    Lost
    Abandoned
    Won
    Open

    What conditional formatting I must use so that if an OPPORTUNITY_STATE is "Won" than it turns the background green, "Lost" or "Abandoned" it turns red and "Open" it turns blue

    • Hi Joe,

      Select the cells A2 to A5 and create 3 rules with the following formulas:

      Green: =$A2="won"
      Red: =OR($A2="lost, $A2="abandoned")
      Blue: =$A2="open"

  3. how to filter different font colors in excel column in old version..
    please help me

  4. Hi Svetlana, I was hoping to get help on the following:
    If the Average of cells B2 through B14 is greater > then the Average of B9 through B14 , fill in the number of the Average of B2:B14. If not (if the other Average is a higher number) fill in that number in the cell.

    This is how I am doing it and it is not working
    =IF(AVERAGE(B2:B14)>AVERAGE(B9:B14),"=AVERAGE(B2:B14)","=AVERAGE(B9:B14)")

    Thank you

    • Hi Valeria,

      You were almost there :)

      =IF(AVERAGE(B2:B14)>AVERAGE(B9:B14), AVERAGE(B2:B14), AVERAGE(B9:B14))

  5. Hi All,

    Just wondering if you can help me with below validation?

    B7 text:I have a drop-down here with Yes or No selection (achieved with data validation)

    B8 text: Here is my challenge. If in B7 Yes is selected I would like to mark B8 cell with grey color. If No selected in B7 I would like B8 to remain blank.

    I tried Conditional formatting (=IF($C$7,"No") then no format set but doesn't working.

    All helps, ideas, suggestions are appreciated.

    Elizabeth

    • Hi Elizabeth,

      IF is not needed in Excel conditional formatting rules because they are conditional per se.

      Try creating 2 rules for B8 with the following formulas:

      Grey: =$B$7="yes"

      No format: =$B$7="no"

  6. Hai Svetlana,
    Thanks for help but I need something different as follows :
    A is the date column, B Column is text which can be repeated in same column with another date, C column is another text which can also be repeated corresponding to column B,
    Now I need formula if date is less than today and if text in column B and C matches then get cell data of day before yesterday with same text combination.

    Pl. help

  7. Hello,

    I am trying the If statement as follows =IF(C2="delivered", "No", "Yes") but everytime excel returns with: the formula contains an error.

    How can I fix this?

    • Hi Sander,

      The formula is correct and works fine in my Excel. Probably you have the List Separator set to ";" in your Windows Regional settings. If so, try replacing commas with semicolons:

      =IF(C2="delivered"; "No"; "Yes")

      • Hi,

        I have an attendance chart for my employees. If they have an infraction, it adds a value like +1 or +.5 based on whether they were late or called in sick. If they work an extra day or overtime, it removes a value like -1 or -.5. I use the COUNTIF formula, but the problem I'm having is if they have more OT than call outs, when they call in sick again, it doesn't adjust the 0 balance to +1 (because there are more negative values in the SUM). Can I use the IF function to keep a running total, so that if their value is already at zero it will still add +1 despite there being more negative numbers in the SUM?

        Example: Callout twice in a week (+2), work 3 extra days (-3, but the max is zero as you can't go negative). Call out (+1), the value is still zero, but it should be 1.

      • Yeah, but that was not the problem. It has something to do with the quote signs,these signs do not work "delivered" but if I do the this =""""" the formula correct itself and works fine.

        Not really sure whats going on but it works.

        Thank you for your help Svetlana

        • Sander,

          This is very strange indeed... Though, sometimes "smart quotes" copied from a web-site may cause a problem and retyping straight quotes in the formula bar fixes it.

    • Nevermind solved it

      Thank you anyway.

  8. Hello Svetlana,

    I am writing this formula in Cell E3 :
    =IF(C4:C9="x",0,15)
    if column c4 to c9 has an "x" or "X" in it it should show zero other wise the value 15. it is showing me #NAME?

    I also tried running :IF(C4&C5&C6&C7&C8&C9="x",0,15). this works for the first cell C4 and the value on E3 changes to zero but as soon as i enter x in c5 or further it shows 15. where am i wrong?
    thank you

    • Hi Asif,

      Just add the AND statement in the logical test, like this:

      =IF(AND(C4="x", C5="x", C6="X", C7="x", C8="x", C9="x"),0,15)

      • Svetlana,

        what i was trying to accomplish was that if any of the cells contain "x" it would show a zero. i used your formula and switched the AND with OR and mission accomplished. thank you so much

  9. hey
    please need your help...

    i want to calculate net absentees of an employee. condition is:

    1- two days per month are allowed (no deduction is applicable)
    2- if absentees exceed 2, then deduction is made.
    3- want to calculate net absentees. where days absent is less than days allowed, the formula shall give ZERO answer.
    4- days allowed cell # C10, days absent F10

    Please help.. thanks

  10. Hi Svetlana

    Please help me to write a formula for the following requirement;

    1) If number of days between cell A & cell B ≤ 50% of number of days between cell A & cell C and Cell E ≥ 60% of cell D then format cell F with "SAFE ZONE" with Green filled.
    2) Else cell F with "CRITICAL" with Red colour filled.

    Respond me asap. Thank you in advance.

  11. H Svetlana

    Have the following:-

    Cell A Cell B Cell C Cell D
    1000 TX 60 -
    1000 BL - 60

    Need only to populated only 1 cell (either C or D)
    with 6% multiplied by Cell A based on status of B (TX or BL). Can this be done using.

    Thanks
    IF

  12. i want to check more than 2 value what will i do..
    Example, if(A1>100,"3.95",A1>150,"3.25",A1>200,"3.00")

    • Please provide me that equation.................

    • You need a nested IF formula in this case:
      =IF(A1>200, 3, IF(A1>150, 3.25, IF(A1>100, 3.95, "")))

  13. Dear Mam,
    if the value of A1 is greater than 200,A1*0.15 Please provide that equation.....

      • thanks

  14. Hi,
    I need formula if date is less than today and text of two columns are matching then get cell data of the same text from corresponding another column.

    Thank You

    • Hi Brajesh,

      You can use a formula similar to this:

      =IF(AND(A1<TODAY(), B1=C1), D1, "")

      Where A is the date column, B and C are the columns to match, and D is the column to extract the data from.

      • Hai Svetlana,
        Thanks for help but I need something different as follows :
        A is the date column, B Column is text which can be repeated in same column with another date, C column is another text which can also be repeated with column B,
        Now I need formula if date is less than today and if text in column B and C matches then get cell data of day before yesterday with same text combination.

        Pl. help

  15. Hi,
    What I am trying to do is I need total of A1 and A2 in cell A3 but once it gets to a certain number I need to have some kind of text in cell A3 says your total is over budget
    I have tried this formula but I did not work
    =sum(a1+a2;if(a3>300;"your total is over budget))
    Thank you

    • Hi Tolga,

      Try this one:
      =IF(A1+A2>300, "your total is over budget", A1+A2)

      • Thank you, you are the best

  16. Hi I am trying to do a formula like J1 125 THEN 2 Else >200 OR <400 Thne 3 how to do please suggest

  17. A1, so good mam

  18. Hi I am trying to do a formula where in d3 it has a percentage and e3 has a number. That's the easy part what I'm stuck on, is I want f3 to be a number where if the d3 is under 5% it's 0, 5-10% is 1 and over 10% is 2 and if e3 is 18.5 or less it's 2 18.6-19.9 is 1 and 20 or over is 0. But I need these scores to only show and add up in f4. Is that even possible?

    • After rereading the page several times I have now been able to figure out the formula myself.

  19. Hello There!
    I would like compare 2 time frames and return a text. In other words, in Column A I have Week Ending 12/31/2015, Column B Week Ending 12/31/2015 and Column C the entered the word New Years next to the week ending date above. If Column A week ending date matches Column B then return Column C text, if not keep looking until the correct week ending date is matched. Let me know if you need further clarification and thank you for your support.

  20. Need a formula for the below.
    If the amount in a another cell is less than $1,500,000.00 the cell should read 60%. If the amount in a another cell equal or greater than $1,500,000.00 up to $2,999,999.00 the cell should read 70%. If the amount in an another cell is greater than and equal to $3,000,000.00 the cell should read 75%. Please help

    • Hi Diana,

      Here you go:
      =IF(A1<1500000, 60%, IF(A1<=2999999, 70%, 75%))

      For the percentages to get displayed correctly, remember to apply the Percent format to the cell.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)