SheetCommand · Excel formulas

How to use the IF function in Excel

Test a condition and return one result when it is true and another when it is false.

The IF function checks whether a cell meets a condition. It returns one value when the test is true and a different value when it is false.

The structure of an IF formula

The syntax is IF(logical_test, value_if_true, [value_if_false]). A logical test can be a comparison such as C2>=1000.

Put literal text results in double quotes. Numbers and cell references do not need quotes.

Sales target example

Use the formula below to show On target when the sale in C2 is at least 1000 and Below target otherwise.

After filling the formula down, check records exactly at the threshold as well as values above and below it.

How to do it

  1. Choose the cell and condition to test.
  2. Enter the result for a true condition.
  3. Add the result for a false condition and test the formula.
Example formula=IF(C2>=1000,"On target","Below target")

Test the boundary with real rows

Let A contain order IDs and B the amounts. With B2=1,200, B3=800, and B4=1,000, the formula labels the rows Large, Standard, Large. The >= comparison includes the 1,000 boundary; > would label B4 Standard.

Enter the formula in C2 and fill down. When the rule changes, verify the boundary and blank amounts, not just a few obvious examples. How blank cells should be treated is a business-rule decision.

OrderAmount (B)Expected result (C)
S-011,200Large
S-02800Standard
S-031,000Large
Example formula=IF(B2>=1000,"Large","Standard")

Text, numbers, and several conditions

Large and Standard are text outputs and need quotation marks. If the output should be numeric, use values such as 1 and 0 without quotes. Check values stored as text before trusting a classification column.

For multiple conditions you can combine IF with AND or OR. Testing each condition in a temporary column makes mistakes easier to find. SheetCommand does not insert IF formulas; this example runs in Excel.

Common IF formula mistakes

Missing quotes around text, using > when >= is intended, and comparing numbers stored as text can produce unexpected results.

Many nested IF functions become difficult to maintain. For several conditions, consider AND, OR, IFS, or a lookup table.

Frequently asked questions

Why is text placed in quotes in an IF formula?

Excel uses double quotes to distinguish literal text from names, references, and functions.

Does SheetCommand write IF formulas automatically?

No. This guide teaches the formula; the tool runs its listed cleanup, sorting, summary, and basic calculation commands.

Sources and further reading

SheetCommand

Check the data before applying conditions

Summarize the report and remove blank or duplicate rows before building the IF formula in Excel.

Use for free →