However, beware that the IF function is deceptively simple.

Formulas that use IF can quickly become advanced as the requirements become more complex.

Contents

The IF function is one of the most widely used functions in Excel.

Basic example - simple formula to return TRUE or FALSE

However, beware that the IF function is deceptively simple.

Formulas that use IF can quickly become advanced as the requirements become more complex.

Sometimes, the IF function doesn’t even make sense for the problem.

Basic example - simple formula to return TRUE or FALSE

To avoid this fate, it pays to understand the basics well.

you’re able to see the result in the worksheet below.

Also, we do not need to provide a value for value_if_false because IF will return FALSE by default.

Basic example - simple formula to return TRUE or FALSE

This formula works fine.

But the output is rather busy and hard to read.

Text values hardcoded into formulas must always be quoted.

Basic example - simple formula to return TRUE or FALSE

Finally, let’s modify the formula to display nothing when a score is not over 80.

We now see an “x” for scores over 80.

Numbers like 80 are not quoted.

Basic example - simple formula to return TRUE or FALSE

Usually, thelogical_testin IF is an expression that will return TRUE or FALSE.

However, numbers and logicaloperatorslike >,<,<>,=, etc., arenot quoted.

A passing score is 70 or higher.

Basic example - modified to return &ldquo;x&rdquo; for scores over 80

Also, note that the logical flow of this formula can be reversed.

Above, we test for failing scores.

Otherwise, return “Fail”.Both formulas will return the same result.

Basic example - final IF formula to mark scores over 80

Which option you choose is a personal preference.

The trick is to combine the IF function with the OR function.

Otherwise, return an empty string ("").

IF function example - Pass or Fail

Notice that the OR function is embedded inside the IF function as the logical test.

The OR function accepts multiple logical expressions.

Ifanyexpression returns TRUE, the OR function will return TRUE.

IF function example - IF this OR that

Only if all logical expressions return FALSE will the OR function return FALSE.

The “B” appears in quotes ("") because it is a text string.

The 80 is not quoted because it is a number.

IF function example - IF this AND that

Each IF statement needs to be carefully “nested” inside another so that the logic is correct.

The idea here is that we are chaining together multiple IF functions to create “else if” logic.

In the example below, the goal is to assign a number to each color.

IF function example - IF this AND OR that

If the color is Red, the result should be 100.

If the color is Blue, the result should be 125.

If the color is Green, the result should be 150.

IF function example - Nested IF formula

Note that this formula will only handle three colors: Red, Blue, and Green".

With any other color, the formula will return FALSE.

In addition, the IF function can also return a formula.

IF function example - Return another formula

The price of other colors should remain unchanged.

If the color is Red, it returns D5*1.2, effectively increasing the price by 20%.

If the color isnotRed, it simply returns D5.

IF function example - If cell contains specific text

IF with wildcards and regex

The IF function does not supportwildcardsdirectly.

However, you’re free to combine IF with other Excel functions to overcome this limitation.

For basic wildcard support, you cancombine IF with COUNTIForcombine IF with SEARCH(as seen above).

IF function example - IF with regular expressions (regex)

This can be done with the pattern “"\b(MN|MT|ND|SD)\b”.

However, just because IF is common doesn’t mean you should always use it.

Excel hasmanyfunctions that don’t need IF to apply “If else” logic.

Excel formula: Mark rows with logical tests

Likewise,COUNTIFSandSUMIFScan count/sum matching values based on multiple criteria without IF.

See101 Functions You Should Know,Dynamic Array Formulas in Excel,andNew Excel Functionsfor more information.

AND returns TRUEonly if all the conditions are met.

Excel formula: Maximum if multiple criteria

If any conditions are not met, the AND function returns FALSE.

OR returns TRUEif any condition is TRUE.

If all conditions are FALSE, the OR function returns FALSE.

Excel formula: Lookup last file revision

When given TRUE, NOT returns FALSE.

When given FALSE, NOT returns TRUE.

Use the NOT function to reverse a logical value.

Excel formula: Max if criteria match

Use the IFS function to evaluate multiple conditions without multiple nested IF statements.

When no match is found, SWITCH can return an optional default value.

Excel formula: nth largest value with criteria

Excel formula: XLOOKUP return blank if blank

Excel formula: VLOOKUP with variable table array

Excel formula: Nested IF function example

Excel formula: Calculate time before expiration date

Excel formula: If cell equals

Excel formula: Only calculate if not blank

Excel formula: If this AND that OR that

Excel formula: If complete show checkmark

Excel formula: If date is between two dates

Excel formula: Date is same month and year

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Excel AND function

Excel OR function

Excel NOT function

Excel IFS function

Excel SWITCH function

Basic example - simple formula to return TRUE or FALSE

Basic example - modified to return &ldquo;x&rdquo; for scores over 80

Basic example - final IF formula to mark scores over 80

IF function example - Pass or Fail

IF function example - IF this OR that

IF function example - IF this AND that

IF function example - IF this AND OR that

IF function example - Nested IF formula

IF function example - Return another formula

IF function example - If cell contains specific text

IF function example - IF with regular expressions (regex)