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

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. Continue reading

Comments page 122. Total comments: 4830

  1. I am try to count how many "Y"'s in a range of columns and convert that into a numeric value and place that value in a different cell.

    Please help

    =IF(SUM(D95:D106)="Y", "1")

  2. Using Logical "IF" formula to determine if date in one cell is < date in another cell =IF(A1<B1,True,False). Returns the correct answer, however when I try to copy it to multiple rows....it does not! If however I go to each row and click the Insert Function menu option...it will change the answer to the correct one! Can't seem to figure it out! Please help

    1. Hi Scarlet,

      Usually copying a formula by selecting the cell and dragging down the fill handle works without a hitch. Are you coping it to other cells in the same column, or somewhere else? For example, the formula is in C1 and you need to have it in, say, C1:C100?

  3. I am trying to add all of the values in column E that have the corresponding number 53017 in column G. I tried this formula but it didn't work.

    =IF(G1:G53=53017,SUM(E2:E58))

    Can anyone advise?

    Thanks!

    1. Hi Lisa,

      You can use the formula similar to this:
      =SUMIF(G1:G53, 53017, E1:E53)

  4. I need help on an Excel formula. I have A group of cells containing text. The text in the range is either "In Process" or "Completed". If any of the cells in the range have text "In Process" the lead cell should return "In Process", if not, it should return "Completed". Please assist.

  5. Hi, how do I get the value if true to be another formula? I have a list of customers (column A), and a list of corresponding dates (column B), I want to set the value if true to be, If cell A1 = Customer x, out put to be date (b1) + 2 days.
    By having the formula as =IF(A1=Customer,"B1+2","") the output is B1+2 whereas I want it to display the date in B1 + 2 days?
    Thansk

    1. Hi Chris,

      Just remove the quotes enclosing B1+2 because they turn any expression into a text string, and apply the Date format to the cell containing the formula:
      =IF(A1="customer",B1+2,"")

  6. In Cell L92 I am try to tally Cells F8, F12, F16, F20 if they say Yes. How do I do this?

  7. Svetlana, why you ignore email from my question?

  8. Can you please help me with following formula

    i have a calculation in Cell A and another calculation in Cell B

    in another cell i want to determine results as following

    if value in cell A and Cell B are greater than or equal to .5 give me true otherwise false

    if values in cell B is blank take value from cell A only and provide results

    1. Hi Kamran,

      You can use a formula similar to this:

      =IF(AND(A1>0.5, B1>0.5), TRUE, IF(AND(A1>=0.5, B1=""), TRUE, FALSE))

  9. Hi Svetlana

    I am looking out for a formula to calculate an incentive structure

    If My CTC is 10000 , and i have given a profit of 45000 , I want an formula to calculate the following slabs in incremental basis.

    If employee achieved 3 times of ctc 5 % incentive
    If employee achieved 3 to 4 times of ctc 10% incentive If employee achieved 4 to 5 times of ctc 15% incentive
    5 to 6 times 20%
    6 to 7 times 25%
    Above 7 times 30 %

    45000 split in 3 slabs

    30000 = 30000 * 5 % Eligibility on 30000
    30000 - 40000 = 10000 * 10 % Eligibility on 10000
    40000 - 45000 = 5000 * 15 % Eligibility on 5000

  10. Hi Svetlana,
    I am referencing a date in cell L57 which is looking at a due date and my formulae works is written as:
    =IF(L57>NOW(),"'OK'","OVERDUE")

    My problem is if I enter a date in another cell,(Say L58)(that tells me that for example, a payment has been made) how can I add a multiple ÍF' function so that it that it references L58 also (which will have a date entry), and then correct cell L57 to read ÓK'' indicating visually that payment has been made.

    Your help would be much appreciated.

    1. Hi Jason,

      You can embed an OR statement in your formula, e.g:
      =IF(OR(L57>NOW(),L58>NOW()),"'OK'","OVERDUE")

      1. Hi Svetlana
        Thankyou so much for your response, however it still does not change the cell response to read OK (when a date value in cell L58 has been entered)

        It is as if it does not overwrite the rule in the first statement.

        Any ideas??

        1. Jason,

          It thought the formula should return OK when the date either in L57 or L58 is greater than the current date (i.e. greater than NOW()).

          If you want it to return 'OK' when either a date in L57 is greater than NOW() or any date is entered in L58, then the formula should read as follows:
          =IF(OR(L57>NOW(), ISNUMBER(L58)),"'OK'","OVERDUE")

          1. Thankyou so much Svetlana, that worked!

  11. I have in mind (maybe an IF) formula I want implement,
    where I have a date of 6-17-15, in one cell (oh,say E7) when we started tracking it as "Open". Cell F7 (7/7/15) would be the date we closed it. Cell G7 would be the days it was open, If we closed it on 7/7/2015, the duration open would be 20 days and the formula would be simply =F7-E7. Correct?
    But, let's say we had not filled in the Cell F7 yet and it is blank. How would I express the formula in Cell G7 to keep a tally of the open days, then when we fill in the G7 cell, it will fill in the open days?
    I hope I explained it well.

  12. Hi Svetlana! I'm trying to figure out an IF statement using dates. Something like, IF(B2=older than three years than NOW(),"Too old", "New"). So simple but I can't figure it out. Thank you!

    1. Hi Michael,

      You can use the DATEDIF function to calculate the difference between 2 dates in years. For example:

      =IF(DATEDIF(B2, TODAY(), "y")>3, "too old", "new")

      1. This worked perfectly! Thank you so much :D

  13. I am trying to get this formula to reference one more cell. if the additional cell contains a date, the formulated cell will be blank.

    any suggestions?

    =IF(ISBLANK(Response_Due_Date),"",IF(Response_Due_Date<TODAY(),"PAST DUE",""))

    1. Hi!

      I think you can add an OR statement to the 1st logical test:

      =IF(OR(ISBLANK(Response_Due_Date), ISNUMBER(additional_cell)), "", IF...

  14. I'm trying to enter two IF functions in one cell for a toggle drop down. How do I connect the two formulas?

    I'm getting #VALUE! with this

    =IF($H$5="step-function",IF(I4<$D$3,$C$4,IF(I4<$E$3,$D$4,IF(I4<$F$3,$E$4,$F$4)))),IF($H$5="continuous",IF(I4=1,$C$4,IF(I4<$D$3,($D$4-$C$4)/($D$3-$C$3)+H6,IF(I4<$E$3,($E$4-$D$4)/($E$3-$D$3)+H6,IF(I4=$F$3,($F$4-$E$4)/($F$3-$E$3)+H6))))))

  15. Hi Svetlana,

    Need a little help. I have 4 text from which i have to choose, if 1st is present then others are false, if 1st missing and second is present then 2nd is true, if 1st and 2nd is missing and 3rd is present then 3rd is true and if 1st 2nd 3rd is missing then, if 4th is present then 4th value is true.

    How do I use IF formula here so that I can get my desired result only from many?

    1. Sorry for the confusion.

      Right now I am using below formula but it seems to be working only with first column.

      =IF(F6" ",F6,(OR(AND(G6=" ",OR(AND(G6" ",OR(AND(H6=" ",OR(AND(H6" ",OR(AND(I6=" ",OR(AND(I6" "))))))))))))))

      Example is mentioned below for your reference

      Column1 Column2 Column3 Column4 Result
      A B -- D Sould be 'A' (A is first present text)
      -- -- C -- Should be 'C' (C is first present text)
      -- B -- D Sholud be 'B' (B is first present text)
      -- -- -- D Should be 'D' (D is first present text)
      -- B C -- Sholud be 'B' (B is first present text)

      1. Took a little time but I have solved this problem.

        Thanks so much for your help for creating this amazing blog though.

  16. This formula is working for me: =VALUE(IF(E12="X","660",IF(E12="","0")))
    but I need to make 2 additions:
    E12="1","660"
    E12="2","660"

    When I've added them I get a #VALUE! entry in the cell. Can you please help me with the right formula? Thanks so much!

    1. Hi Shannon,

      I am not sure why you use the VALUE function in the formula. The following one works for me:
      =IF(OR(E12="X", E12=1, E12=2), 660, IF(E12="", 0, ""))

  17. Hi Svetlana,
    How do i set the formula if i want to calculate the bonus based on 20% of their basic salary, and the salary is cap at maximum $6000. Meaning to say if someone basic salary is at $8000, still he will received the bonus at $6000x20%=$1200. And if someone basic salary is at $5000 then i would be $5000X20%=$1000. Your advice please. Thanks

    1. Hi Low,

      Supposing column A is salary, you can use a formula like this:
      =IF(A2<6000, A2*20%, 6000*20%)

  18. I have to use and “IF” formula to fill cells in a column at the end of a table. I have to formulate the new column so that if there is a 2-1 ratio from Field D data to field C data then field E data has a good result, otherwise it is a bad result. I have gotten this far, =IF(D2>C2, "Success","Failure") but cannot calculate the ratio. Seems simple, but I cannot figure out how to calculate that D2 needs to be twice the amount of C2, I can only figure it to be greater. I am new to Excel.

  19. Area. TargetDate. Code. Aa. Aug 1 2015. 01. Ab. Aug 1 2015. 02. Aa. Aug 2 2015. 03. Ab. Aug 2 2015. 04. My question is what formula should i use to display automatically this value in the nxt table. . Aug 1 2015 Target. Area. Code. Aa. 01. Ab. 02. . Please help me! Thanks

  20. Hai Svetlana,
    Still waiting for your valuable reply for given below :
    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

    1. Brajesh,

      Sorry, I cannot figure out a formula for this task.

  21. 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

    1. Hi Abdul,

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

  22. 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

    1. 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"

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

  24. 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

    1. Hi Valeria,

      You were almost there :)

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

  25. 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

    1. 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"

  26. 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

  27. 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?

    1. Nevermind solved it

      Thank you anyway.

    2. 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")

      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

        1. 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.

      2. 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.

  28. 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

    1. 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)

      1. 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

  29. 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

  30. 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.

  31. 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

  32. 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")

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

    2. Please provide me that equation.................

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

    1. Hi Hari,

      Here you go:
      =IF(A1>200, A1*0.15, "")

      1. thanks

  34. 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

    1. 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.

      1. 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

  35. 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

    1. Hi Tolga,

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

      1. Thank you, you are the best

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

  37. A1, so good mam

  38. 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?

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

  39. 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.

  40. 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

    1. 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.

  41. how can I use If function so that a value is set if true otherwise the user determine the vale
    for example : If( B4="good" , 0, enter a value)

  42. can I use it in fill color?

  43. How do I set up a formula to equal 1 if one cell is the same letter as another or 0 if there is no exact match. For example:
    B1= C, C1=C therefore the value is 1

    or IF B1=C and C1=D, the value is 0

  44. I need a if statement on the below example:

    if employe = Government, Banking , Insurance and >300 it should give 3 and more than >1000 it should give 5

  45. Hi can you help me write a formula for multiple if's. I am trying to make the cell say if G18=2 then print 5.00%, if G18=3 then print 10.00%. If G18=4 then print 15.00%. Going up to if G18=10 then print 45.00%. However when I put in multiple if statements it says TRUE if there is a value in the range or FALSE if not. The formula I put in is, =IF(G18=2,"5")=IF(G18=3,"10")=IF(G18=4,"15")=IF(G18=5,"20")=IF(G18=6,"25")=IF(G18=7,"30")=IF(G18=8,"35")=IF(G18=9,"40")=IF(G18=10,"45").
    Please ac==can you help as I cannot find how to do it.

    1. done it don't worry, I did this instead =IF(G14=2,5,IF(G14=3,10,IF(G14=4,15,IF(G14=5,20,IF(G14=6,25,IF(G14=7,30,IF(G14=8,35,IF(G14=9,40,IF(G14=10,45,)))))))))

  46. Hello,
    I would like to know the formula for this problem.
    409 is in A1 cell.
    i tried with if formula - I am not getting the result.
    out of 409 units - for the first 100 units sold at 2.60, 101-150 units
    sold at 3.15, 151-200 units at 3.55 and 201-409 units sold at 3.85.

    kindly guide me

  47. I have an issue with excel 2010. I have a cell B24 with a formula that produces a number result. I also have cell D13 with a formula that produces a number result as well.

    In a third cell I want the results of B24 and D13 to be compared. Currently, the formula in this third cell is =if(D13=B24,"OK","STOP!!") however it is not working... Please help. :)

    1. Hello Wikelani,

      The formula is absolutely correct and I don't see any reason for it not working. Does it deliver wrong results in your worksheet?

  48. Hi.

    I have spent several hours on this IF formula and it's still really not doing what i want.

    =IF(F3I4;F3*1,45;IF(F3>J4;F3*1,4;IF(F3>K4*1,35;IF(F3>L4*1,3;)))))

    H4=1000 I4=1500 J4=3000 K4=5000 L4=10000

    What i am trying to obtain is that if value in F3 is between 0-1000 the amount in F3 is to be multiplied by 1,50. if the amount is between 1001-1500 it is to be multiplied by 1,45 and if F3 is between 1501-3000 it is to be multiplied by 1,40 and so on

    Seems to be working for the first 2 but then it continues to multiplie all the other with 1,45

    Any help would be very appreciated

  49. Hi Vegil,

    You can embed the COUNTIF function in the logical_test argument, like this:
    =IF(COUNTIF($B$1:$B$6,$A1)>1, "More than 1 values match in Column B", "")

  50. Hello,

    I want to compare column A and B and if the value of column B has more than one match from column A the formula should return an error. For example, I have entered "America" in A1 and if there are more than 1 "America" in B column values it will return "More than 1 values match in Column B". Can you help me give the excel formula for that?

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 :)