Open In App

Excel IF Function

Last Updated: 03 Dec, 2024

J

Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The IF function in Excel is one of the most powerful and commonly used formulas that allows you to perform logical tests and return different values based on whether the condition is true or false. If you’ve ever needed to check whether a value meets certain criteria, then the IF function is the tool you’ll want to master. In simple terms, the IF function evaluates a condition and returns one result if the condition is true and another if it’s false. The best part is that its syntax is clear and can be combined with other functions to create more complex formulas.

Let’s explore how the IF function works in Excel, its syntax, and practical examples of its usage to help you get started.

Excel-IF-function-With-Examples-(1)

Excel IF Function

What is IF Function in Excel

The IF function in Excel is a powerful tool that allows users to perform logical tests within a spreadsheet. It checks whether a given condition is true or false and returns different values based on the outcome. The basic syntax of the IF function is:

Excel IF Statement

The IF function serves a single purpose, i.e., to run tests for specific conditional statements. 

=IF(condition, value_if_true, value_if_false)

where,

  • condition: The logical test or condition to evaluate (e.g., A1 > 10).
  • value_if_true: The value to return if the condition is true.
  • value_if_false: The value to return if the condition is false.

This function enables dynamic decision-making in spreadsheets by automating responses based on conditions, making it a valuable tool for data categorization, analysis, and productivity.

The IF function supports the logical operators( <,>,<=,>=,=)  to test logical arguments.

IF Formula in Excel

The basic IF formula checks a logical condition and returns one value if the condition is true, and another if the condition is false. For example, you can test if a cell’s value is greater than a certain number and return custom messages or values based on that condition.

Example Formula:

=IF(A1 > 10, "Greater than 10", "10 or less")
  • If A1 contains a value greater than 10, the formula returns “Greater than 10”.
  • If A1 contains 10 or less, it returns “10 or less”.

This basic IF formula helps simplify decision-making in spreadsheets, allowing you to categorize or analyze data automatically based on defined conditions.

Note: You have the flexibility to define both the condition and the return values.

How to Use IF Function in Excel (With Example)

Suppose you want to determine if all the students in a class PASSED or FAILED their tests based on their scores. Instead of manually checking each student’s score, you can define the IF condition for one cell.

Step 1: Enter Data in Spreadsheet

First, open MS Excel and enter the relevant data into your worksheet. For example, the data should include students’ names in Column A and their corresponding marks in Column B. We want to check whether each student has passed or failed based on their marks.

image

Enter data into the sheet

Step 2: Select the Cell and Enter the IF Formula

Now, select the cell where you want to display the pass/fail status. For instance, go to Cell C2 and enter the following formula:

=IF(B2>=35, "Pass", "Fail")

This formula checks if the marks in Cell B2 are greater than or equal to 35. If the condition is true (marks ≥ 35), it will display “Pass” otherwise, it will display “Fail”.

Excel IF function

Applying to One Cell

Step 3: Apply the Formula to the Rest of the Cells and Preview Result

Select Cell C2, hover over the bottom-right corner until the cursor changes to a “+” (fill handle), then drag it down to apply the formula to the rest of the column.

Excel IF function

Applying to all the Cells

How to Use the IF with AND Function in Excel (With Example)

The IF function with AND in Excel allows you to check multiple conditions at once. It returns a value if all the specified conditions are true, and another value if any condition is false.

Syntax: IF(AND(condition 1, condition 2), Value if true, Value if false)

For example, =IF(AND(A1>90, B1>90), “A1 Grade”, “Fail”) will return “A1 Grade” if both A1 and B1 are greater than 90, otherwise, it will return “Fail”..

Step 1: Enter the Data into the Sheet

Start by entering the data into your worksheet. For this example, let’s assume Column A contains scores for Subject 1 and Column B contains scores for Subject 2.

Excel IF function

Enter Data into the Sheet

Step 2: Enter the IF with AND Formula

Next, in Cell C2, enter the IF with AND formula to check if both scores are greater than 90.

=IF(AND(A2>90, B2>90), "A1 Grade", "Fail")

This formula checks if both A1 and B1 are greater than 90. If both conditions are true, it will return “A1 Grade”; if either of the conditions is false, it will return “Fail”.

Excel IF function

Enter IF with AND Formula

Step 3: Drag down the Formula and Preview Results

Drag the Formula to apply it to rest of the cells.

Excel IF function

Preview Results

How to Use the IF with OR Function in Excel

The IF function with OR in Excel allows you to test multiple conditions and return a result if at least one condition is true. The syntax is:

=IF(OR(condition1, condition2), value_if_true, value_if_false)

For example, if you want to check if a student’s score in either Subject 1 or Subject 2 is greater than 90, you can use the OR function. If either condition is true, the formula will return “Pass”, otherwise, it will return “Fail”.

Step 1: Enter the Data

First, enter the data into your worksheet. For example, let’s assume Column A contains the scores for Subject 1, and Column B contains the scores for Subject 2.

Excel IF function

Enter data into the sheet

Step 2: Enter the IF with OR Formula

Now, in Cell C2, enter the IF with OR formula to check if either of the two subject scores is greater than 90:

=IF(OR(A2>90, B2>90), "Pass", "Fail")

This formula will return “Pass” if either A1 or B1 is greater than 90. If neither condition is true, it will return “Fail”.

Excel IF function

Enter the IF with OR Formula

Step 3: Drag Down and Apply the Formula

Drag down and apply the formula to other rows as well

Excel IF function

Drag down the formula

Note: The IF with OR function in Excel will only evaluate numeric values. If the cell contains text or non-numeric values, it will be considered as TRUE, as Excel treats text as a non-zero value. Ensure that the cells contain only numeric data for accurate evaluations.

How to Use the IF with NOT Function in Excel

The IF with NOT function in Excel is used to negate a condition. It returns TRUE if the condition is FALSE, and FALSE if the condition is TRUE. Essentially, it reverses the result of the condition being tested. It’s syntax is:

IF(NOT(Condition 1), Value if true, Value if false)

For example, if you want to check whether the color of a ball is not red, the formula would be:

=IF(NOT(A1="Red"), "Selected", "Rejected")
  • If A1 is not red, it will return “Selected”.
  • If A1 is red, it will return “Rejected”.

Step 1: Enter Data into the Sheet

First, enter your data. For this example, we’ll assume that Column A contains the color of balls.

Excel IF function

Enter data

Step 2: Enter the IF with NOT Formula

In Cell B1, enter the IF with NOT formula to check if the ball color is not red. The formula will return “Selected” if the color is not red, and “Rejected” if it is red.

=IF(NOT(A1="Red"), "Selected", "Rejected")

This formula checks if the value in A1 is not “Red”. If the condition is true (i.e., the ball color is not red), it returns “Selected”; otherwise, it returns “Rejected”.

Excel IF function

Use IF with NOT Function

Step 3: Apply the Formula to Other Rows and Preview Result

Drag down the formula and Preview Results

Excel IF function

Drag down the Formula and Preview Results

This way, the IF with NOT function allows you to check and reverse the outcome based on a specific condition (in this case, checking if the ball is not red).

Nested If Function in Excel with Examples

A Nested IF function in Excel is used when you need to evaluate multiple conditions and return different results based on the conditions. In simple terms, it’s a combination of multiple IF functions within one formula to handle more than one condition. The syntax is:

=IF( condition1, Value if true1 ,IF(Condition2, Value if true2, Value if false2)). 

Below is an example of the Nested if function.

Step 1: Enter your Data

Let’s take a dataset of students with their marks and we have to assign the division based on the marks.

Step 2: Enter Nested IF Formula

Formula used is : =IF(B2>=60,"1st Division",IF(B2>=30,"2nd Division",IF(B2>=10,"3rd Division","Fail")))
Excel IF function

Enter Formula

This formula checks multiple conditions:

  • If the marks in B2 are greater than or equal to 60, the formula returns “1st Division”.
  • If the marks are between 30 and 59 (i.e., B2 >= 30 but less than 60), the formula returns “2nd Division”.
  • If the marks are between 10 and 29 (i.e., B2 >= 10 but less than 30), the formula returns “3rd Division”.
  • If the marks are less than 10, the formula returns “Fail”.

IF Statement to Return Another Cell

In Excel, “return another formula with IF” means using the IF function not just to return static text or numbers but to output the result of another formula. This approach dynamically applies calculations or functions based on specific conditions.

For example:

We want to assign a discount based on the purchase amount in cell B2:

  • 20% Discount for purchases of 500 or more.
  • 10% Discount for purchases between 200 and 499.
  • No Discount for purchases less than 200

Step 1: Open Your Spreadsheet and Enter Data

Open Excel with existing data or enter new data and go to the cell where you want the discount to appear (e.g., C2).

image-

Open Excel and Enter data

Step 2: Start with the First Condition

Type the IF formula:

=IF(B2>=500,"20% Discount"

This checks if the value in B2 is greater than or equal to 500.

If TRUE, it returns “20% Discount”.

Step 3: Add the Second Condition

If the first condition is FALSE, add another IF function for the next range using the below formula:

=IF(B2>=500,"20% Discount",IF(B2>=200,"10% Discount"

This checks if the value in B2 is greater than or equal to 200 (but less than 500, since the first condition is FALSE).

If TRUE, it returns “10% Discount”.

Step 4: Add the Final Condition

Add a condition for all remaining cases (less than 200), use the below formula:

=IF(B2>=500,"20% Discount",IF(B2>=200,"10% Discount","No Discount"))

If neither of the first two conditions is TRUE, it returns “No Discount”.

Step 5: Press Enter

Hit Enter to complete the formula. The formula dynamically calculates the discount based on the value in B2.

image

Preview Result

IF Function with Specific Text

When you need to check whether a cell contains specific text, you can use the IF function combined with SEARCH or REGEXMATCH to achieve this. This allows you to perform conditional actions based on whether a given text string exists within another cell.

For example, if you want to check whether a cell contains the word “approved” and return “Yes” if true, or “No” if false, you can use:

Step 1: Enter data into the Sheet

Open MS Excel and Enter data into the sheet

image

Enter the data

Step 2: Type the Formula

Select the Cell, where you want to type the Formula and Press Enter

=IF(ISNUMBER(SEARCH("approved",A2)),"Yes","No")

Understand the Components

SEARCH(“approved”, A1):

  • Looks for the text “approved” in cell A1.
  • If found, it returns the starting position of the text (a number).
  • If not found, it returns an error.

ISNUMBER(…):

  • Checks whether the result of SEARCH is a number (indicating the text was found).
  • Returns TRUE if a number exists, otherwise FALSE.

IF(ISNUMBER(…),”Yes”,”No”):

  • Uses the result from ISNUMBER to determine the output:
    • “Yes” if the text is found.
    • “No” if the text is not found.
image-

Enter the Formula

Step 3: Drag the Formula and Preview Results

Drag down the formula to apply it to other cells as well and preview Results.

image-

Preview Results

Conclusion

The IF function in Excel is an invaluable tool for anyone looking to automate decision-making within their spreadsheets. Whether you’re using it for basic comparisons, more complex scenarios involving AND or OR, or even combining it with other formulas to return dynamic results, the IF function can significantly enhance your productivity and efficiency. By understanding how to set up conditions with true or false outcomes, and applying it to specific texts or numerical values, you can tackle a wide range of tasks, from data analysis to customized reports. Mastering the IF function opens the door to more advanced Excel techniques, making it a fundamental skill for anyone working with spreadsheets.

Excel IF function – FAQs

How do you use the IF function in Excel?

To use the IF function in Excel, follow these steps:

  1. Select a cell
  2. Enter the formula
  3. Define the condition
  4. Set the true value
  5. Set the false value
  6. Close the formula
  7. Press Enter

How to use if function in Excel with 2 conditions?

To use the IF function with 2 conditions, you can nest an IF function within another IF function or use the AND/OR functions. For example, =IF(AND(condition1, condition2), value_if_true, value_if_false) tests if both conditions are true.

How do you write an ifs then formula in Excel?

The IFS function allows multiple conditions without nesting. The syntax is =IFS(condition1, value_if_true1, condition2, value_if_true2, …). It returns the value for the first true condition it finds.

How to use if function for 4 conditions?

Follow the the steps given below:

  1. Start the formula
  2. Enter the first condition
  3. Add the second IF function
  4. Add the third IF function
  5. Add the final value
  6. Close all parentheses
  7. Press Enter

How to use if function excel with text?

Follow the steps given below:

  1. Select the cell
  2. Start the formula
  3. Enter the condition
  4. Set the true value
  5. Set the false value
  6. Close the formula
  7. Press Enter


J

News
Improve
Discuss
Do you want to advertise with us?Click here to know more

Excel VLOOKUP Function - Excel Guide for Beginners

article_img
How to do Vlookup in Excel - Quick StepsPrepare Your DataEnter the VLOOKUP Formula >>Press EnterUse a Cell Reference for Flexibility Copy the Formula for Multiple RowsThe VLOOKUP function is one of the most widely used tools in Excel for looking up and retrieving data from a table. Whether you’re working with a single sheet or multiple workbooks, VLOOKUP allows you to search for a value in one column and return a related value from another. If you're new to Excel or still getting the hang of formulas, this guide is for you. We will cover everything from the basics of how VLOOKUP works to practical examples that show how to search data across sheets, troubleshoot common issues, and master the VLOOKUP formula for any task.Excel VLOOKUP FunctionWhat is the VLOOKUP Function in ExcelThe term VLOOKUP stands for Vertical Lookup. It is designed to search for a specific value in the first column of a table (lookup column) and retrieve corresponding data from a different column in the same row.Syntax of VLOOKUP FormulaVLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])Arguments:1. lookup_value: The value you want to search for (e.g., a specific ID, name, or product code).
Read More

Editing Excel Macros in Excel

article_img
Excel Macro is a set of actions that can be recorded, saved, used multiple times. This feature saves us a lot of time when dealing with repetitive tasks and huge data sets. We can always make changes to an existing Macro in Excel. There are two ways to record and run macros: Excel Commands Excel Visual Basic for Applications(VBA).1. Copying a Macro Code We can reuse the existing macro code while creating new Macros. For example, if you have existing macros created using the record function, we can reuse the code to write new macros. To open the code follow the below steps: Select Tools --> Macros --> Visual Basic Editor. Copy code from the existing macros(use Command + C) and paste(use Command + V) in the new macro2. Renaming a Macro Follow the below steps to rename a Macro in Excel: Select Tools --> Macros --> Visual Basic Editor. Select name on the left plane.Edit the name.3. Deleting a Macro Follow the below steps to delete a macro in Excel: Select Tools --> Macros --> Macros... Select the macro to be deleted. Click on the minus(-) symbol at the bottom.Select yes to delete the macro.
Read More

Best Microsoft Excel High-Paying Jobs with Excel Skills in 2024

article_img
Are you ready to unlock a world of opportunities with Microsoft Excel? In today’s data-driven job market, mastering Excel is essential for launching a successful career, whether you're a fresher or an experienced professional. In this article, we will cover the high-paying Excel jobs available in 2024, including crucial roles like data analyst, business analyst, and many more. We'll explore the qualifications needed for these positions, along with salary estimations to help you understand your earning potential. Whether you’re looking for Excel jobs for freshers or seasoned professionals, we’ll also dive into options for Excel freelancing jobs and work-from-home jobs in Excel. Equip yourself with the knowledge to excel in your career and take the first step toward a lucrative future!Best Microsoft Excel High-Paying Jobs with Excel Skills in 2024Table of ContentWhy choose a career in ExcelWhy Excel Skills Are Essential for Your CareerEssential Excel Skills Required to Boost Your Resume Best Microsoft Excel High-Paying JobsFinancial AnalystsData AnalystAdministrative Assistant Accountants Project ManagersManagement ConsultantRetail Store ManagersBusiness Analyst Market Research A
Read More

AI in Excel: Top 20 Excel AI Tools in 2025 (Free/Paid)

article_img
The integration of AI in Excel is transforming the way professionals manage, analyze, and visualize data. Whether you're handling large datasets, performing financial analysis, or automating repetitive tasks, AI-powered tools can significantly improve efficiency and accuracy. In 2025, advanced Excel AI tools are making complex tasks easier by offering features like data cleaning, predictive analytics, smart automation, and AI-driven insights.In this guide, we’ve gathered a list of the top 20 Excel AI tools for 2025 that are reshaping how users interact with Excel.Table of ContentBest AI Tool in Excel: Top Picks for 2025Top 10 Free Excel AI Tools in 2025Top 10 Excel AI ToolsAI in Excel: OverviewIn Excel, an AI tool (Artificial Intelligence tool) refers to an add-in or extension that leverages artificial intelligence to enhance your spreadsheet experience. These tools can automate tasks, improve data analysis, and generally make you more productive.Excel has always been a powerful tool for data analysis, but with the integration of AI tools, it has transformed into a smarter, more intuitive platform.Best AI Tool in Excel: Top Picks for 2025Explore the below AI tools designed for auto
Read More

What Is the Difference Between VAR.S Function and VAR.P Function in Excel?

Functions in Excel are the pre-defined formulae used to obtain a certain value and to perform calculations using the specific value in a certain order. The basic functions are SUM, AVG, MAX, MIN, etc used for the range of cells. In order to obtain the correct results from the function, the correct syntax of the functions is required. In this article, we will discuss VAR.P FUNCTION & VAR.S FUNCTION, the difference between VAR.P FUNCTION & VAR.S FUNCTION, and demonstrate how to calculate each in an excel sheet. VAR.P Function The VAR.P function is classified as an Excel statistical function. This function returns the variance of a given set of values. This was introduced in the 2010 version of MS Excel.Variance is a statistical measure used across a range of values ​​to determine how much the values ​​differ from the mean. As a financial analyst, the VAR.P function helps me calculate sales variances. Portfolio managers often use this feature to measure and track portfolio risk. Formula of VAR.P Function =VAR.P(number1,[number2],...) number 1 (mandatory argument): This is the first argument corresponding to the population.  number 2 (optional arguments): where number arguments
Read More

K

Gestep Function In Excel

GESTEP is a function in Microsoft Excel that is used to check whether the given number is greater than the given threshold value(given step value). It returns 1 i.e. True , if the number is greater than the step value and, It returns 0 i.e. False , if the number is lesser than the step value. Formula of GESTEP function: =GESTEP(number, [step]) Here, Number= given number that is to be tested.Step=defines the step size with which given number is compared. Step is completely optional. If step value is not given it is considered as 0 Example: Lets suppose we have following numbers and steps, and we have to use the GESTEP function. Step 1: Now we will write =GESTEP(A2,B2), here A2 and B2 are the number and step values respectively. Now press enter. Step 2: Now we can say that the Result value is 1 i.e. True . This is because the number value>Step value. Step 3: Now Drag and select from C2 to C5 and all the values for each row will be automatically calculated. Step 4: This is the final result of the given question. Common error: #VALUE! = This occurs if any of the values or both the values in the GESTEP function are non-numeric.
Read More

Function and Sub in Excel VBA

article_img
In Visual Basic, the functions and sub-procedures play similar roles but have different or unique characteristics. However, both perform a programmed task. They utilize a set or group of commands to deliver the required results. The key difference between the sub and the functions is that a sub-procedure generally does not return a result whereas functions tend to return a result. Hence if there is a need for having a value post execution of tasks, then place the VBA code under a function or otherwise place the code under a sub-procedure. In Excel, there is the availability of large numbers of VBA functions that could be utilized in the development of new VBA codes. Such functions are referred to as Built-in functions. With the increase in the size of a VBA program, both Functions and Sub-procedures play a crucial role in the management and performance of VBA code. Functions in VBA A function in VBA can be defined as a procedure that executes a piece of code or instructions and post-execution, it returns the value of the tasks performed. A function is hence invoked using a variable. Functions are directly called in the spreadsheets by using excel based formulas. An excel VBA functi
Read More

How to use MINIFS function in Microsoft Excel

article_img
The MINIFS function in Excel is a powerful tool for filtering and analyzing data. It allows you to find the smallest numeric value in a range of cells that meet one or more specified requirements. This can be useful for a variety of tasks, such as finding the lowest price for a product in a specific category, finding the shortest delivery time for a product, finding the highest test score for a student in a particular class, or finding the lowest employee salary in a department. What is the MINIFS Function in Excel The MINIFS formula in Excel is a combination of the MIN and IF functions. To use it, we provide a range of values to evaluate for the minimum, along with one or more sets of criteria. Each set of criteria consists of a range and a condition, then the MINIFS would return the minimum value that meets all the specified criteria. To define the criteria, MINIFS supports logical operators like (>,<,<>,=) and wildcards like asterisks(*) and question marks (?) to match the partial text or patterns. Note: Note: This feature is available on Windows or Mac if you have Office 2019, or if you have a Microsoft 365 subscription. MINIFS Function FormulaThe below formula will
Read More

How to use the IFS function in Excel

article_img
The IFS function in Excel acts as a keen partner, making choices for your information. It's perfect when you have different rules and wish to grant prizes based on those rules. Rather than getting misplaced in complicated enlightening, IFS assists your information in getting to where it ought to go. It's interesting that once you have several conditions and have to decide which one is redressed. What is the IFS Function in ExcelExcel's IFS function functions as a smart traffic cop for your data which means you can easily highlight the data’s value from greater to smaller. It checks the conditions you provide and awards the correct prize when the first condition strikes the bullseye. There will be no more twisted traffic jams of nested IF statements. You simply align your criteria and incentives, and IFS handles the rest. It's like having a shortcut that goes to different goodies depending on your search criteria. Instead of bewildering a lot of options, in a way you get a simple route that guides your data where it needs to go. The below-mentioned image is the basic function argument for IFS: Basic Argument Function of IFSWhen to use the IFS FunctionIf looking into the IFS function
Read More

How to Debug a User Defined Function in Excel VBA

article_img
Debugging a User Defined Function (UDF) in Excel VBA can feel like a detective mission where you search for clues to fix issues in your code. When a custom function doesn’t deliver the expected results, it can disrupt your workflow and lead to frustration. Fortunately, debugging tools in VBA make it possible to identify exactly what's going wrong and why. In this article you will learn the effective techniques to debug your UDFs, helping you find errors, understand how your code runs, and ensure your functions work seamlessly. Whether you're a beginner or an experienced user, mastering these debugging skills can save you time and turn coding headaches into problem-solving victories.Table of ContentWhat is a User Defined Function in Excel What is Debugging in Excel VBA How to Create a User-Defined Function in Excel VBAHow to Debug a User-Defined Function in Excel VBACommon Debugging Tools in Excel VBAUDF works in debug mode but it doesn't give value into the cell: 9 Best ways to ResolveHow to Debug a Custom Function in ExcelWhat is a User Defined Function in Excel A User Defined Function (UDF) in Excel VBA is a custom function created by users to perform specific tasks or calculatio
Read More
three90RightbarBannerImg