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 140. Total comments: 4830

  1. 18,19,43 in a column with test date at next column. 18's validity is 1 year,19's 5 year and 43's 6 month how can we show the due date in excel at a glance.

  2. Hi,

    I am using the =if(isnumber(search) to look for partial value. However, in my list I have 180 and 18. the end result will only pick up 18 instead of 180.
    What other functions can I use to ensure that both 18 and 180 will be pick up?

  3. =SUMIF(January!A5:A200,January!U4,January!B5:B200)
    The January!B5:B200 has names in it but it is coming up 0. i am sure that i am using the incorrect function

  4. Cell A1 is a hand entered date. Cell B1 is a total dollar value. Cell C1 is # of months. Starting with Cell D1 and going right are 12 more columns for the months of the year. Need a formula in D1 that says this: If the date in A1 is between January 1st and 31st, then take B1 and divide it by C1. Once I can get that, I can nest it with ifs to cover all of the months. My problem is how to do the date portion. Can you help??

  5. 1. i have a table with 2 columns (A,B)
    2. column A has a list of control measures and
    column B has 2 options(yes or no)
    3. what i want is if the answer is "yes" to NOT extract the control measure in a new worksheet and if the answer is "no" to EXTRACT

    e.g A1 (warning signs in place?) B1 (no)
    A2 (workers are aware of local emergency procedures?) B2 (yes)

  6. Hi Svetlana Cheusheva and Alexander,
    could you please help in solving my problem
    my excel column contains -5:55 -2:26 -2:19 -1:38 1:06 1:16 1:17 2:20 like wise nearly more than 100
    my result column to have Neg Neg Neg Neg 1-2 HR 1-2 HR 1-2 HR 2-3 HR
    could you please provide me an IF formula
    am using 2007 excel
    Remaining-TAT(h:m) TAT
    -2:19 Neg
    -1:38 Neg
    1:06 1-2 HR
    1:16 1-2 HR
    1:17 1-2 HR
    1:20 1-2 HR
    2:02 2-3 HR
    2:05 2-3 HR

  7. I am trying to add 1.5 to values higher than 3. Values 1-3, I need to remain the same. How can I do this?

    Ex. person enters 4 in a cell it is automatically calculates to 1.5
    Person enters 2 in a cell it remains the sames.

  8. Hi,

    Building a transcation register. Currently using this formula =IF(D13>0,H12-D13,H12+F13).
    But, when I copy this to the rows below I'll get the last result shown in the rows below. I would like to check the cells for values, before using the above mentioned formula. So when there are no numbers in cell D14 and F14, it will return an empty cell in H14. If there are numbers in either D14 or F14 use above if formula.
    Thanks for your help!

  9. Hi,

    1) I need a formula in I16 that can check cell B12 for # of servings (if any).
    example: B12="Sangría Rojo (2 glasses per guest). 10 servings."
    2) If B12=x servings then x*h12
    3) If B12 does not contain x servings then h8*h12
    example no servings: B12="Sangría Rojo (2 glasses per guest)."

    Thank You

  10. Hi Svetlana,

    I want to create the formula that select the cell P if the life time less than 10 years ,I put this formula =IF(S5<10,P5,"")but I also need to have same result if life time "1-5", (between 1 to 5) and I put this =IF(AND(S8<10,S8= 1 - 5),P8,"") didn't work, could you please help me.

    Thank you,

  11. i need a formula for first date is less then 2nd date how to check

  12. Hello Svetlana,

    I need a formula that could generate email from from a given list of names.

    I need the formula to be in such a way that it could satisfy both the below condition's.

    For ex:

    if there is:

    Condition 1:

    ==>> First name + Middle name-1 + Middle name-2 + last name
    Ex : ( how ) + ( are ) + ( you ) + (today )

    to generate : how.are.you.today@gmail.com

    Condition 2 :

    ==>> First name + Middle name-1 + Middle name-2 + last name
    Ex : ( how ) + ( isblank ) + (isblank) + (today )

    to generate : how.today@gmail.com

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    looking forward to hearing from you soon.

    Thanks in advance.

  13. Hi,
    I have to find difference between two dates (Ex. A1 & B1). B1'=(now)' . I want results to display either one of these-"Minutes Ago","Hours Ago", "Days Ago","Week's Ago","Months Ago". whichever is the least.

    EX:A1= 2/16/2014 7:05:05 PM, B1=2/18/2015 2:29:13 PM.
    My formula gives me this result =1 years 12 months 367 days

    DATEDIF formula {=DATEDIF(A1,B1,"y")&" years Ago "&DATEDIF(A1,B1,"m")&" months Ago"&DATEDIF(A1,B1,"d")&" days Ago".
    This does not give Hours and Minutes. Can you help?And also is there a way to use If formula to display only 1 result i.e, "Minutes Ago" if this is the closest? Please help !

  14. Hello Svetlana,
    Your site is very helpful!
    Could you kindly help me with below:
    I need a formula where if the cell in particular row contain values from a table, then return value "trade", otherwise "unknown". The list contains over 100 values, therefore the ISNUMBER(SEARCH) function cannot be used.

    "Table" example:
    11 trade
    12 trade
    13 trade
    14 trade
    15 trade
    186 trade
    ...

    List example:
    13 trade
    13,14 trade
    15,2222 trade
    2882,2213 unknown
    14,11,75,2882,2213 unknown

    1. 14,11,75,2882,2213 trade

  15. Hello Svetlana.
    Great Work.
    I need to find a two pairs of value in a cell, A/B OR C/D.
    A = 5 [value in cell C31]
    B = 5 [value in cell C31]
    C = 8 [value in cell C32]
    D = 8 [value in cell C32]
    blank cell, give me nothing.

    How can i do to find A or B ( same with C or D)

    =IF(C33="A OR B";(C$31);IF(C33="C OR D";(C$32);""))

    also one question, how can i make a addiction of various IF conditions? Like:

    =IF(C33="A OR B";(C$31);IF(C33="C OR D";(C$32);"")) + =IF(D33="A OR B";(D$31);IF(D33="C OR D";(D$32);"")) + =IF(E33="A OR B";(E$31);IF(E33="C OR D";(E$32);""))

  16. Using IF function write a formula if " Date" is Blank pick the Value from "System number", else name it as Date In.

    data
    system date
    d322 16/2/2015
    f3532 17/3/2015

  17. Hi. I have a word in cell A62. I want to search the range A5:A45 to see if it contains my word. If it finds the word, then i want to highlight that row and then insert a formalua, =IF(B41="a","yes","no") in the Q coloum of that row.
    Is this possible?

  18. i want to check if the data in one cell is contained in any other or not. what is the code??

  19. HELLO,
    i need a formula to show that if my first cell is greater than the average then to show me 0 otherwise to show the difference between the first cell and the average(some cells are 0) ,so i was trying =IF(D3>D$291;TRUE=0;FALSE=D3-D291) but doesn't work .THANK YOU IN ADVANCE!!!

    1. Hello Sofia,

      Just enter the following formula:
      =IF(D3>D$291; 0; D3-D$291)

  20. I have 2 cells that contains month and year. The first cell is date when qualification was received. Second cell is date when qualification expires. The 3rd cell below these 2 cells I want to say "Expired", "1 Month Left", "3 Months Left" based on these dates.

    Please help me.

    Thank you very very very much!!!

  21. Ah brilliant much appreciated seems i fell at the last hurdle.
    cheers
    James

  22. i am trying to set up an IF function where it searches a cell for a word that has the letters UCI if true gives the result 2.2 if false gives 2.8. i have done this but doesnt seem to work :(
    =IF(ISNUMBER(SEARCH(E3="UCI")),"2.2","2.8")

    please help

    1. Hello James,
      =IF(ISNUMBER(SEARCH("UCI",E3)),"2.2","2.8")

  23. Hi, i want an output with two conditions. That is if A1=I OR II OR III and if B1<=5 then the output in C1 should reflect as 'yes' otherwise it should be 'no'.
    I typed as =if(and(A1="I", A1="II", A1="III",B1<=5),"yes","no").This is not working.
    Kindly let me know the error or is this formula totally wrong? Thanks in advance.

    1. Aengus, thank you for your help.

      Shiva, you can also use the formula below (the result will be same):
      =IF(AND(OR(A1="I", A1="II", A1="III"),B1<>"", B1<=5),"yes","no")

      1. Thank you Alexander. The result was correct. Elated to learn new techniques.
        Cheers.

    2. Here you go
      =IF(OR(A1="I",A1="II",A1="III"),IF(AND(B1<=5),"YES","NO"))

      1. Thank you Aengus. The formula worked wonderfully well.Delighted.
        Cheers.

  24. Class Name Test 1 Rank
    year 9A Student 1 20
    year 9A Student 2 30
    year 9A Student 3 20
    year 9A Student 4 21
    year 9A Student 5 22
    year 9A Student 6 52
    year 9A Student 7 54
    year 9A Student 8 14
    year 9A Student 9 25
    year 9A Student 10 26
    year 9A Student 11 21
    year 9A Student 12 24
    year 9A Student 13 22
    year9B student 1 23
    year9B student 2 54
    year9B student 3 52
    year9B student 4 52
    year9B student 5 21
    year9B student 6 22
    year9B student 7 12
    year9B student 8 22

    1. I am sorry, it is not quite clear what result you want to get. For us to be able to assist you better, please post a small sample workbook with your data and the expected result on our forums. Our support team will look into your task and try to help.

  25. Hi. I want to extract a number from a cell(B2) at an exact time. I have two times on my sheet, one is the start time of an event and the other is the actual time right now. When there is a differance of 2 minutes between both times, then i want to extract the number in cell(B2) and i want the value to remain there.
    My sheet is connected to a website and the sheet is updated every second, so the value in cell B2 is constantly changing.
    Is this possible???

    1. Hello Aengus,

      I am sorry, but there is no way to fulfill your task using formulas. Since you want the value to remain in the cell, a VBA macro is needed for this task. You can look for it on http://www.mrexcel.com or http://www.excelforum.com.

      1. Hi,
        I have a two workbooks 1)Masterlist and 2)Saleslist

        Master list have columns description, unit and unit price. Fixed number of rows.
        Sales list have columns description, unit, unit price, saleqty and amount. Rows increases on ever sales.

        It will be wonderful some body can help with the code to fill the cell unit price in the workbook Saleslist when I enter matching description of the item as in Masterlist.

  26. Thanks for posting If Function in a very easily manner.

    can you tell me the function to extract text from cell

    Eg: Paid to Sub cont Rafiq/against balance payment.
    Paid Sub cont Shafeeque/against part payment.

    In this I want to extract only from the text sub cont to /.

    1. I am sorry, your task is not very clear. For us to be able to assist you better, please post a small sample workbook with your data and the expected result on our forums. Our support team will look into your task and try to help.

  27. Hi,

    I have a master sheet and individual sheets (with the details) for a survey.

    I want to be able to populate the individual sheets with simply putting a Y or N on the master sheet. Is this possible?

    ie A clients details and their consent to receiving marketing, research & volunteering are on the master sheet. Can I then automatically populate the individual sheets from the master?

    Thanks
    Debra

    1. Hello Debra,
      You can enter the formula like the one below to the cells on your individual sheets:
      =if(MasterSheet!$A$2="y", MasterSheet!$C$2, "")

      That means that if cell A2 is in the master sheet contains "Y", copy data from MasterSheet!$C$2.

  28. Hello,

    I'm having trouble making a formula that will return a date or a value. i.e. I'm making a time off request form, and sometimes the cell will have a single date (2/11/15) and sometimes it will have multiple dates (2/11/15 to 2/12/15). I can get the single date to fill by formatting my formula cell to "date," but I cannot get the range to show up. I want the exact input from the cell to show up regardless of being a date or "text" as the multiple dates would be considered.

    My formula that I'm using is =IF(A7,A7,"").

    I've tried using a variety of arguments in front of the second A7, but I still haven't gotten the results I want. I don't want to format the original cell to text if I can avoid it.

    1. I found my answer. Thank you.

      =IF(ISBLANK(A7),"",A7)

      This does exactly what I need.

  29. Hi I am struggling working this out any help would be fantastic.
    Basically I have 3 businesses I need to keep track of the mileage, I have a spreadsheet set up for that. However I want to keep individual records on the sheet for each business.
    so the business is one of three "photography" "building" "design" in cell D6 I want to take the mileage from k6 and add it to a separate cell depending on the business displaying the output at g2, g3 or g4 and I want this to run through the sheet. so it checks column d for which business then depending on the business it takes the result from column k and place the sum totals in either g2,g3, or g4

    I am at a loss to sort this. not even sure its possible. but help is appreciated please.

    1. Hello Patrick,

      A formula can return the result only in a cell where it is entered. Most likely, you simply need to place three IF formulas into cells G2, G3 and G4 that will show the result or keep blank according to the specified conditions. If you want to get a sum, then you may also need to use the SUMIF function.

      If you can send us a small sample workbook with your data to support@ablebits.com, we’ll try to assist you better.

  30. Hi there,

    I'm using a SUMIF formula to return a required number.
    Now, i need a formula to return a required text.
    if i enter name in c1 and it matches with b1 i need an answer.
    for example:
    a1 b1 c1
    rey 502 rey
    may 502 may

    hope you could help me.

    thanks,

    1. Hello Clarice,

      I am sorry, your task is not quite clear. For us to be able to assist you better, please post a small sample workbook with your data and the expected result our forums. Our support team will look into your task and try to help.

  31. Hi, I am trying to work out a formula that says:

    Work out the average of F5:F11 IF B5:B11 contains data

    Is there any chance you could help?

    Many Thanks
    Rachel

    1. Hi Rachel,

      =IF(COUNTA(B5:B11)=7,AVERAGE(F5:F11),"")

  32. Hi there, i am trying to figure out a formula for not leaving cells blank. For instance, if B2 has the word "debit card" the C2 cannot be left blank. If B2 contains the word "cash" then C2 can be left blank.

    Does such a formula exist?

    Many thanks
    Lara

  33. Hi,

    I have successfully used on A3 cell: =IF(ISBLANK(A2),"",IF(A21,A2<=2),"IMPROVEMENT NEEDED")))

    But Can't use on A4 cell: (A1 cell is a number i.e. 10000)
    =IF(A3="Unsatisfactory",A1*100%,IF(A3="Improvement Needed",A1*105%))

    it shows:"FALSE". how to make A4: if A3 is vacant as per above formula, A4 will be A1*1

    1. Hello Zakaria,

      I am sorry, your task is not quite clear. Please post a sample workbook with some variants of your data (1 sheet – 1 variant) on our forums and include the result you want to see in A4. Our support team will look into your task and try to help.

  34. I tried using the If formula for my data but I just could not get it to work.

    Example:
    I have set a target for John and if he meet the target the cell will display the Rebate (10%) percentage, if not it will display 0%.
    Rebate: 10&
    QTD: 17,275
    Target: 12,500

    How do i go about setting the formula for this?

    Thanks so much!

    1. >cell will display the Rebate
      =IF(E2>=12500, "10%", "0%")

      Where E2 is the cell with a target for John.

  35. Hi ,

    I am using nested IF for age
    =IF(M7<39,"Cohort C",IF(AND(39<=M7,M7<48),"Cohort B","Cohort A"))

    however the age i am using DATEIF formula as below :
    =DATEDIF(K7,TODAY(),"Y") & " Years, " & DATEDIF(K7,TODAY(),"YM") & " Months, " & DATEDIF(K7,TODAY(),"MD") & " Days"

    which result as i.e 35 years , 2 months, 1 days

    How can i specify the date as above format in the nested IF statement ?

    1. Hi Luxmi,

      It's difficult to give any advice without seeing the real data. It will be helpful if you can give more details about the value in cell M7 and other cells the formula refers to.

      1. sorry it is actually M7 = Age . However , for this scenario the age is purely calculated by the year only.

        How if i use below formula to calculate the (M7 cell) age & use this M7 cell to do nested if statement :
        =DATEDIF(K7,TODAY(),"Y") & " Years, " & DATEDIF(K7,TODAY(),"YM") & " Months, " & DATEDIF(K7,TODAY(),"MD") & " Days"

        which result as i.e 35 years , 2 months, 1 days

        how can i specify the age using this format ?
        =IF(M7<39 years, 00 Month 00 Day,"Cohort C",IF(AND(39 Years 00 Month 00 Day<=M7,M7<48 years 00 Months 00 Days),"Cohort B","Cohort A"))

        1. Hello Luxmi,

          Please specify the age in the same way as you calculate data in cell M7, i.e. using this formula:
          =IF(DATEDIF(K7,TODAY(),"Y") < 39,"Cohort C", IF(DATEDIF(K7,TODAY(),"Y") < 48,"Cohort B","Cohort A"))

  36. Using an IF statement, can more than one action be included if the condition is met? For example, if A1=x then (B1 = "true" and C1=y) else (B1 = "false" and C1=z)

    1. Hi Nancy,

      There is no way to do this in a single formula because a formula can return the result only in a cell where it is entered.

      You can simply use two formulas:

      For B1: =IF(A1="x", true, false)
      For C1: =IF(A1="x", "y", "z")

      If you need to change a lot of cells, then a VBA macro will be a better solution.

  37. Hi just wanna ask help on this.I'm confused on how to exactly put many functions in the formula. The legend are the following:

    "B" - 74 below
    "D" - 75-79
    "AP" - 80-84
    "P" - 85-89
    "A" - 90 up

    For example:I actually tried to enter =IF(E16<75,"B","D")=IF(E16=80<85,"D","AP")=IF(E16=.....ETC...

    pls help me...

    1. Hi Michelle,

      You need to use a nested IF function like this:

      =IF(E16>=90, "A", IF(E16>=85, "P", IF(E16>=80, "AP", IF(E16>=75, "D", "B"))))

  38. I want to figure out a way in column A1 to column A1000 is equal to the word "Done" then enter the current date in the coresponding column B1 to column B1000

    1) Enter Done in A1 and B1 gets automatically updated with date and time
    2) Enter In Progress in A2 and B2 get nothing updated
    3) Enter Done in A3 and B3 gets automatically updated with data and time
    4) and so on....

    Status Timestamp for Completion
    A1 Done B1 02/06/2015 5:17:33 PM
    A2 In Progress B2
    A3 In Progress B3
    A4 Done B4 02/06/2015 5:17:34 PM

    trying:

    =IF(A1:A10="Done",=(NOW())
    or
    =IF(A1:A10="Done,B1:B10=(NOW()))
    or
    ?

  39. Hello, Please help me I need following formula.
    I need formula of column C and D
    C = matching part part will be colored.
    D = Matched or not, in sequence of column B.

    problem attached for ready reference with following link.

    https://www.dropbox.com/s/xbkh51pp9n9vt28/Formula.xlsx?dl=0

    1. Hi Imran,

      The following formula seems to return the results you want:

      =IF(OR(NOT(ISERR(SEARCH($A$2,B2))), NOT(ISERR(SEARCH($A$3,B2))), NOT(ISERR(SEARCH($A$4,B2)))), "matched", "not matched")

      Or even better - the array formula (remember to press CTRL + SHIFT + ENTER to enter it:

      =IF(SUM(--(NOT(ISERR(SEARCH($A$2:$A$4,B2))))), "matched", "not matched")

  40. Hi,

    Please i need a help, i want a formular for two dates intervals. A suming i have my start date and want to know the ending dates.
    For instance my start date of paying back loan is 08/15/2014 and i'm paying for 6 months, what will be the formular for the ending date.

    Thanks

    1. Hello Francis,

      Please use this formula:
      =DATE(YEAR(A1),MONTH(A1)+6,DAY(A1))

      Where A1 is the cell with your start date, 6 is the number of months.

  41. Hello,

    Looking for an if statement which may not exist. At work we run an SQL that reports locations of specific items. The location field is always xxx-xxx-xx. For example 224-111-03 would be aisle 224, 111th spot, 3rd shelf. I am trying to figure out if I can write an if statement where if the value is between 200-000-00 and 299-999-99, then 1. Or really anyway to manipulate the "224-111-03" so I can work with the locations.

    Thanks

    1. Hello Daniel,

      You can use both variants. Please specify the one you prefer and we will help you with the formula.

  42. hi,

    i have this check list with a checkbox, and i need to know how i can make the question status cell to display a text(done, pending) while changing the cell color (red to green),when i select one of the checkbox answer.

    ex. do you have a list of traces on PCB? []yes []no []n/a [question status]

  43. HOW TO USE ROUND OFF COMMENT WITH SUM

  44. i trying to put a formula which searches a specific word from the excell cell string and if ts there then then type "True" or false accordingly.

    1. please help me out over this

  45. Hi, I am creating a spreadsheet to analyse UK horse racing. There are 60 courses under the "Course List" column. In the "Course" column I have listed the meetings taking place each day for the next 12 months, 1175 in total. I am using the following formula in the "Total Meetings" column to extract the number of meetings for each racecourse during the next 12 months
    Total Meetings:
    =COUNTIF($B$2:$B1176,$D2)

    I would now like to add another column which shows the number of meetings remaining after todays races have completed. e.g. if there are 25 meetings in total for a race course, each time a meeting is completed reduce the number of meetings remaining by 1 and display in "Remaining" column next to each course in the "Course List"

    RACE DATE COURSE Course List Total Meetings Remaining
    1-Feb-15 MUSSELBURGH AINTREE 21
    MUSSELBURGH CHELMSFORD CITY 18
    2-Feb-15 PUNCHESTOWN LINGFIELD PARK 54
    WOLVERHAMPTON SOUTHWELL 60
    KEMPTON PARK CHELMSFORD CITY 55
    ASCOT AYR 12
    BANGOR-ON-DEE 22
    MUSSELBURGH 7

    Any suggestions please?

    Thanks

  46. hi,

    I need a help in IF formula.
    I have a sheet column AA8 TO AA132 with different due dates, AB column has status as ND,F,WP. I want to change the ND to blank if due date is today.

    thanks

    1. hi,

      could you please help me on this formula
      =IF(AA8=TODAY(), IF(AA8= "ND", ""))
      if ND with due date works fine, but any other words LIKE F, WP,CO ETC RESULT SHOWS FALSE

      THANKS
      VJ

      1. Hello Vijay,

        It is difficult to recommend you anything without seeing your data. If you can post your sample workbooks and the result you want to achieve on our forum, our support team will try to help.

        1. I want to highlight one cell of any column When we move the cursor anywhere in the excel sheet. when we will move the cursor up & down then highlight position also move in column only.

          ex-
          let we choose B column and we work in A,C,D column.
          now if we will work in A1 or C1 or D1 cell then B1 cell should be highlight.
          if we will work in A3 or C3 or D3 column then D3 should be highlight.

          plz give the solution.

  47. Hi,

    I was wondering if you could help me. I am trying to format a worksheet where if there is something (in my case columns H, J, L, and N all contain dates) in column H and no value in column I for that same row, the row text turns a different color. Then the same for J to K, L to M, and N to O. Is there an easy way to do this? Maybe I am overthinking? If it's not possible to change the row text color, then just the relative column with the date (H, J, L, N). Thanks!

    1. I am sad that this is not something that can be done. It would make things so much easier.

      1. Hi Gracie,

        In fact, you can do this by creating Excel conditional formatting rules. For example, if you want to highlight a row that has a date in column H but no value in column I in the same row, you use this formula:

        =AND($H2<>"", $I2="")

        Where row 2 is your first row with data (not including the column headers).

        Please check out the following tutorial for more details:
        How to change the row color based on a cell's value in Excel

        1. This is terrific! I cannot even put into words how helpful this is. Thank you so much!!!!

  48. Hi,

    I am doing a project and I need to use the IF function in cell B14 to see if the average in B10 is > the value of each individual average in cells C10,D10,E10, and F10. I tried =IF(B10>C10:F10,"Yes!","No") and =IF(B10>C10,D10,E10,F10,"Yes!","No") both aren't working.

    1. Never mind. I just got it.

  49. I have a table with different tasks and Price of that task. I want to be able to put in a task code and get have a cell read "direct" or "indirect". Would if function work best?

  50. How do you use an If function to count how many characters there are in a cell.
    The question is to ask if there are less than four characters in a certain cell?

    1. Hi Kimberly,

      You can use the LEN function to count the number of characters in a certain cell, and then you can embed it in the IF function. For example:
      =IF(LEN(A1)<4, "good", "bad")

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