IF Formula Generator

Describe the conditions and what each one should return. The IF formula builds as you type, as a nested IF and as the equivalent IFS, with each step explained. Copy either with one click.

If

Values: a cell (B2), a number (90) or text (Pass), which gets its quotes added. Start with = to enter a formula as written (=B2*0.1).

Your formula appears here, e.g. =IF(A2>=90,"A",IF(A2>=80,"B","F"))

Nothing is uploaded. The formula is built in your browser as you type.

An IF formula generator writes an Excel IF formula from a rule you fill in as choices: which cell to test, how to compare it, what to compare it with, and what to return. Take a gradebook with the score in A2 and "Yes" in B2 when the coursework is in. The rule is A+ for 90 or more with the coursework in, B for 80 or more, C for everything else. The generator writes it both ways:

=IF(AND(A2>=90,B2="Yes"),"A+",IF(A2>=80,"B","C"))
=IFS(AND(A2>=90,B2="Yes"),"A+",A2>=80,"B",TRUE,"C")

We pasted both into Excel for Mac. A score of 92 with "yes" returned A+, and 85 with "No" returned B. The lowercase "yes" still matched, because Excel's = ignores case.

How to use the IF formula generator

  1. In the first "If" box, type the cell to test (A2), pick a comparison such as "is at least", and type the value to compare it with (90).
  2. To test two things at once, click "+ Add AND / OR condition". Choose AND when every part must be true, or OR when any one is enough. The AND and OR function pages explain both.
  3. Type what to return when the condition is true: A+.
  4. For the next band down, click "+ Add another condition (a nested IF)". Each condition is checked only when every one above it was false.
  5. Type what to return when none of the conditions is true.
  6. Both formulas update as you type, with a line under them explaining each step. Copy one with its copy button, paste it into the first result cell (say C2), and fill down.

The formula is built in your browser. Nothing is uploaded, and there's no sign-up or usage limit.

Which one to copy comes down to who opens the file. The nested IF works in every version of Excel. IFS needs Excel 2019 or later, including Microsoft 365; in anything older, the cell shows #NAME?.

What the generator writes for each comparison

You pickThe condition in the formula
equalsA2=90
does not equalA2<>90
is greater thanA2>90
is at leastA2>=90
is less thanA2<90
is at mostA2<=90
contains the textISNUMBER(SEARCH("urgent",A2))
is blankA2=""
is not blankA2<>""

Values and results follow one rule. A cell reference (B2) or a number (90) goes in without quotes. Anything else is text and gets them: Pass becomes "Pass", and a quote inside the text is doubled, as Excel requires. Start with = to put in a formula as written, so a result of =B2*0.1 returns 10% of B2. A result left blank becomes "", which shows as an empty cell.

The tested cell can be a formula too. Type =LEN(A2), pick "is greater than" and type 10, and the condition reads LEN(A2)>10.

While something is missing, the generator says what, in plain words: which condition, which part, and whether it needs a cell or a value. Type a column header such as Score where the cell belongs and it tells you Score isn't a cell.

Put the strictest condition first

A nested IF returns the result of the first condition that's true and never looks at the rest. Write the bands in the wrong order and the later ones are dead:

=IF(A2>=60,"Pass",IF(A2>=90,"Distinction","Fail"))

A score of 95 passes the first test and returns Pass. Distinction can never come back. Nothing errors, so a formula like this can sit in a workbook for months. Microsoft's support page on nested IFs shows the same mistake with commission rates, where every sale above the lowest threshold earns the lowest rate.

The generator checks conditions top to bottom, the same way. Put the highest threshold in the first box: at least 90 returns Distinction, at least 60 returns Pass, otherwise Fail. The explanation lines read the chain in order ("If A2 is at least 60... Otherwise, if A2 is at least 90"), and a wrong order is easier to spot there than inside the brackets.

Why IFS returns #N/A, and how the generator avoids it

IFS has no "otherwise" argument. When none of its tests is true, it returns #N/A. The fix is a final test that is always true, TRUE, followed by the fallback value. The generator ends every IFS formula that way, as in A2>=80,"B",TRUE,"C"), so the IFS and the nested IF return the same answer on every row.

Nested IF has its own version of this problem. Leave off the last argument and IF returns FALSE. The generator always writes an otherwise value, and leaving that box blank gives "".

IF a cell contains text: why a wildcard doesn't work

=IF(A2="*urgent*","Call back","") never matches anything. The = comparison doesn't treat * as a wildcard, so it checks whether A2 holds the literal text *urgent*, asterisks included. COUNTIF and SUMIF read wildcards. IF's equals sign doesn't.

"Contains the text" writes the version that works:

=IF(ISNUMBER(SEARCH("urgent",A2)),"Call back","")

SEARCH returns the position where the text starts, or an error when it isn't there, and ISNUMBER turns that into TRUE or FALSE. In our Excel test it flagged "URGENT: call back". The generator's warning under the formula covers the two catches: SEARCH ignores case, and it matches part of a word, so "cat" is found in "Concatenate".

Blank cells, numbers stored as text, and dates

The generator never sees your cells, so it can't catch these. Each makes a correct formula return the wrong answer.

Blank cells count as zero. =IF(A2<60,"Fail","Pass") marks every empty row Fail. Make the first condition "A2 is blank" and leave its result blank:

=IF(A2="","",IF(A2<60,"Fail","Pass"))

Numbers stored as text. Excel ranks any text above any number, so a score imported as the text "85" passes A2>=90. These cells are usually left-aligned with a green triangle in the corner. Convert them to numbers before you trust the column. The same trap exists on the value side: type $1,000 as the comparison value and it goes in as the text "$1,000", and > then compares alphabetically. The generator warns about this and tells you to type the number without quotes or symbols, as 1000.

Dates. A date typed as 1/1/2025 is text as well, and gets the same warning with "is at least" or "is less than". Type =DATE(2025,1,1) as the value instead. The leading = passes it through as written, and the condition becomes A2>=DATE(2025,1,1). =TODAY() works the same way for "overdue" checks.

Writing an IF formula in Excel without the generator

Type the formula into the cell, or go to Formulas > Logical > IF to open the Function Arguments dialog (the Formula Builder on a Mac), which has boxes for Logical_test, Value_if_true and Value_if_false. For a nested IF, the next IF goes in Value_if_false. Hand-written nested IFs usually break on brackets. One closing bracket in the wrong place, or a stray comma, and Excel answers with "You've entered too many arguments for this function". While you edit, Excel colours each pair of brackets differently, which helps you find the stray one.

Typing is quicker for a single test with two outcomes, such as =IF(B2>0,"Paid","Due"). At the other end, a long ladder of bands (tax brackets, a ten-step commission scale) is better as a table than as any IF. Put the thresholds in one column and the results in the next, and look them up with approximate match. The VLOOKUP generator writes that formula and warns that the first column must be sorted smallest to largest. To map exact codes to results, such as region codes to managers, SWITCH is shorter than a chain of IFs.

What the generator can't do

  • It builds the formula without reading your data, so it can't tell you that a column holds text numbers or empty rows.
  • It separates arguments with commas. If your Excel uses semicolons, as German, French and many other European setups do, replace the commas between arguments after pasting. Commas inside quoted text stay.
  • There's no "begins with" or "ends with". Make the tested cell a formula instead: =LEFT(A2,3) with "equals" and INV tests whether A2 starts with INV.
  • Comparisons ignore case, and there's no case-sensitive option. After pasting, change the test to EXACT, as in EXACT(B2,"PAID"), or swap SEARCH for FIND, which is case-sensitive.
  • One condition joins its parts with AND or with OR, not both. "(A and B) or C" works as two conditions that return the same result. For "A and (B or C)", edit the pasted formula: AND(A2>=90,OR(B2="North",B2="South")).
  • It takes up to 5 parts per condition and 20 conditions. Excel allows 64 nested IFs, but a 20-branch formula is already more than anyone can check by eye.

The IF function and IFS function pages go through each argument with more worked examples.

Questions

Can you have 2 IF statements in one cell?

Yes. Put the second IF in the first one's value_if_false argument, as in =IF(A2>=90,"A",IF(A2>=80,"B","C")). Excel works through the tests left to right and returns the result of the first one that is true. In Excel 2019 or later, including Microsoft 365, IFS writes the same chain without the nesting.

How do I use IF with AND and OR in Excel?

Make AND or OR the first argument of IF. =IF(AND(A2>=90,B2="Yes"),"A+","B") returns A+ only when both tests are true, while the same formula with OR returns A+ when either one is. You can put one inside the other, as in AND(A2>=90,OR(B2="North",B2="South")).

How many nested IFs can you have in Excel?

Excel accepts up to 64 nested IF functions in one formula. Long before that, the formula becomes hard to read and easy to get wrong, and Microsoft's own guidance is not to go near the limit. For more than a handful of bands, a lookup table with VLOOKUP or XLOOKUP is easier to check and to change.

Why is my IF formula returning the wrong value?

Most often the conditions are in the wrong order, so a broad test such as A2>=60 catches rows meant for a later one such as A2>=90. Otherwise the cell may hold a number stored as text, which Excel ranks above every real number. Or the cell is empty, and an empty cell counts as zero in a numeric test.

How do I use IF with dates in Excel?

Compare against the DATE function, not a date in quotes: =IF(A2<DATE(2025,1,1),"Old","New"). A date inside quotes is a piece of text, so Excel compares it as text and the answer is wrong. Use TODAY() for today's date, as in =IF(A2<TODAY(),"Overdue","").

Should I use IF or IFS for multiple conditions?

Use IFS when everyone who opens the file has Excel 2019 or later, including Microsoft 365, because it reads as one flat list of tests and results. Use nested IF when the workbook might open in an older version, where IFS shows #NAME?. Either way, end IFS with TRUE and a fallback value, or it returns #N/A when no test is true.

Why does my IF formula return FALSE instead of a blank?

Because the formula has no value_if_false argument, and IF returns FALSE when the test fails and nothing is given. Add "" as the third argument to show an empty-looking cell. That cell holds text, though, so use 0 instead if other formulas do arithmetic on the column.