ShareYourGroupShareYourGroupExcel Formulas

Logical functions

IF function in Excel

IF checks a condition and returns one value when it is true and another when it is false.

IF is how a spreadsheet makes a decision. It asks a yes-or-no question about your data and gives one answer for yes and another for no. Pass or fail, due or paid, reorder or in stock: almost every workbook that does more than add uses IF somewhere.

Syntax

=IF(logical_test, value_if_true, [value_if_false])
ArgumentWhat it is
logical_testA condition that is either true or false, such as C2>=33.
value_if_trueWhat to return when the condition is true.
value_if_falseWhat to return when it is false. If you leave it out, the result is FALSE.

Examples

Each result below is what Excel itself showed for the formula on the sample sheet.

Sample sheet: Marks of eight students in three subjects. One Science mark is missing (cell D6 is empty).
ABCDE
1NameClassMathsScienceEnglish
2Asha8A788591
3Ravi8B455260
4Meena8A928879
5Kabir8B334138
6Tara8A6772
7Joy8B889084
8Neha8A546158
9Imran8B787369

How it works

IF has three parts, in the order you would say them: if this is true, then show this, otherwise show that.

The condition is a comparison, built with one of these signs.

SignMeaning
=equal to
<>not equal to
>greater than
<less than
>=greater than or equal to
<=less than or equal to

Text needs quotation marks

Text inside a formula goes in double quotation marks: "Pass". Numbers and cell references do not. =IF(C2>=33,Pass,Fail) gives the error #NAME?, because Excel takes Pass and Fail for names it has never heard of.

Comparing text ignores capital letters: "yes" equals "YES".

Showing nothing

To leave the cell looking empty when the condition fails, return two quotation marks: =IF(B2>0,B2*C2,""). Keep in mind that the cell then holds empty text, not a number, so a formula that later multiplies it may show #VALUE!. When the result feeds other sums, returning 0 is safer.

An IF inside an IF

For more than two outcomes, put a second IF in the place of the "otherwise". The fourth example gives three grades. Excel checks the conditions from left to right and stops at the first true one, so the order matters: test the highest boundary first.

Nesting two or three deep is fine. Beyond that the formula becomes hard to read and easy to break. Better choices for many bands:

Testing two things at once

IF takes one condition. To require two things together, or either of two, wrap them in AND or OR: =IF(AND(C2>=33,D2>=33),"Pass","Fail"). See AND, OR and NOT.

Common mistakes

In Google Sheets

IF works identically in Google Sheets.

Related functions

Every result on this page was calculated in Microsoft Excel (version 16.0, build 20326) on 12 November 2026, not typed by hand.

This is an independent help site. It is not connected with or approved by Microsoft. Excel and Microsoft 365 are trademarks of Microsoft Corporation, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.