If function excel for string

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

For example:

  • =IF(A2>B2,»Over Budget»,»OK»)

  • =IF(A2=B2,B4-A4,»»)

Argument name

Description

logical_test    (required)

The condition you want to test.

value_if_true    (required)

The value that you want returned if the result of logical_test is TRUE.

value_if_false    (optional)

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

Cell D2 contains a formula =IF(C2="Yes",1,2)

  • =IF(C2=”Yes”,1,2)

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

Cell D2 contains the formula =IF(C2=1,"YES","NO")

  • =IF(C2=1,”Yes”,”No”)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

Formula in cell D2 is =IF(C2>B2,”Over Budget”,”Within Budget”)

  • =IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

Formula in cell E2 is =IF(C2>B2,C2-B2,"")

  • =IF(C2>B2,C2-B2,0)

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

Formula in Cell F7 is IF(E7=”Yes”,F5*0.0825,0)

  • =IF(E7=”Yes”,F5*0.0825,0)

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

Problem

What went wrong

0 (zero) in cell

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

#NAME? in cell

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Connect with an expert. Learn from live instructors.

See Also

IF function — nested formulas and avoiding pitfalls

IFS function

Using IF with AND, OR and NOT functions

COUNTIF function

How to avoid broken formulas

Overview of formulas in Excel

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Normally, If you want to write an IF formula for text values in combining with the below two logical operators in excel, such as: “equal to” or “not equal to”.

Table of Contents

  • Excel IF function check if a cell contains text(case-insensitive)
  • Excel IF function check if a cell contains text (case-sensitive)
  • Excel IF function check if part of cell matches specific text
  •  Excel IF function with Wildcards text value
    • Related Formulas
    • Related Functions

Excel IF function check if a cell contains text(case-insensitive)

By default, IF function is case-insensitive in excel. It means that the logical text for text values will do not recognize case in the IF formulas. For example, the following two IF formulas will get the same results when checking the text values in cells.

=IF(B1="excel","yes","no")
=IF(B1="EXCEl","yes","no")

The IF formula will check the values of cell B1 if it is equal to “excel” word, If it is TRUE, then return “yes”, otherwise return “no”. And the logical test in the above IF formula will check the text values in the logical_test argument, whatever the logical_test values are “Excel”, “eXcel”, or “EXCEL”, the IF formula don’t care about that if the text values is in lowercase or uppercase, It will get the same results at last.

Excel IF function check if a cell contains text1

Excel IF function check if a cell contains text1

Excel IF function check if a cell contains text (case-sensitive)

If you want to check text values in cells using IF formula in excel (case-sensitive), then you need to create a case-sensitive logical test and then you can use IF function in combination with EXACT function to compare two text values. So if those two text values are exactly the same, then return TRUE. Otherwise return FALSE.

So we can write down the following IF formula combining with EXACT function:

=IF(EXACT(B1,"excel"),"yes","no")

Excel IF function check if a cell contains text case-sensitive1

Excel IF function check if part of cell matches specific text

If you want to check if part of text values in cell matches the specific text rather than exact match, to achieve this logic text, you can use IF function in combination with ISNUMBER and SEARCH Function in excel.

Both ISNUMBER and SEARCH functions are case-insensitive in excel.

=IF(ISNUMBER(SEARCH("x",B1)),"good","bad")

Excel IF function check if part of cell matches specific text1

For above the IF formula, it will Check to see if B1 contain the letter x.

Also, we can use FIND function to replace the SEARCH function in the above IF formula. It will return the same results.

 Excel IF function with Wildcards text value

If you wan to use wildcard charcter in an IF formula, for example, if any of the values in column B contains “*xc*”, then return “good”, others return “bad”. You can not directly use the wildcard characters in IF formula, and we can use IF function in combination with COUNTIF function. Let’s see the following IF formula:

=IF(COUNTIF(B1:B4,"*xc*"), "good","bad")

Excel IF function with Wildcards text value1


  • Excel IF Function With Numbers
    If you want to check if a cell values is between two values or checking for the range of numbers or multiple values in cells, at this time, we need to use AND or OR logical function in combination with the logical operator and IF function…

  • Excel EXACT function
    The Excel SEARCH function returns the number of the starting location of a substring in a text string.The syntax of the EXACT function is as below:= EXACT (text1,text2)…
  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria.= COUNTIF (range, criteria) …
  • Excel ISNUMBER function
    The Excel ISNUMBER function returns TRUE if the value in a cell is a numeric value, otherwise it will return FALSE.
  • Excel IF function
    The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE….
  • Excel SEARCH function
    The Excel SEARCH function returns the number of the starting location of a substring in a text string.…

How can I assign a value to cells if it’s neighbour contains a specific string?

For example, fields in column A:

    dog11
    cat22
    cow11
    chick11
    duck22
    cat11
    horse22
    cat33

The syntax in column B would be:

=IF(SEARCH("cat",A1),"cat",IF(SEARCH("22",A1),"22","none"))

It always picks up the first TRUE cell, but drops when the value is not true.

MERose's user avatar

MERose

3,8687 gold badges51 silver badges77 bronze badges

asked Aug 8, 2012 at 15:03

Csongor's user avatar

SEARCH does not return 0 if there is no match, it returns #VALUE!. So you have to wrap calls to SEARCH with IFERROR.

For example…

=IF(IFERROR(SEARCH(«cat», A1), 0), «cat», «none»)

or

=IF(IFERROR(SEARCH(«cat»,A1),0),»cat»,IF(IFERROR(SEARCH(«22″,A1),0),»22″,»none»))

Here, IFERROR returns the value from SEARCH when it works; the given value of 0 otherwise.

flodel's user avatar

flodel

87k20 gold badges182 silver badges219 bronze badges

answered Aug 8, 2012 at 16:33

shipr's user avatar

shiprshipr

2,7691 gold badge23 silver badges32 bronze badges

1

You can use OR() to group expressions (as well as AND()):

=IF(OR(condition1, condition2), true, false)

=IF(AND(condition1, condition2), true, false)

So if you wanted to test for «cat» and «22»:

=IF(AND(SEARCH("cat",a1),SEARCH("22",a1)),"cat and 22","none")

answered Aug 8, 2012 at 15:06

Brad Christie's user avatar

Brad ChristieBrad Christie

99.9k16 gold badges154 silver badges199 bronze badges

2

=IFS(COUNTIF(A1,"*cats*"),"cats",COUNTIF(A1,"*22*"),"22",TRUE,"none")

answered Jun 13, 2020 at 22:48

vstepaniuk's user avatar

vstepaniukvstepaniuk

6035 silver badges13 bronze badges

1

Содержание

  1. IF function
  2. Simple IF examples
  3. Common problems
  4. Need more help?
  5. IF function
  6. Simple IF examples
  7. Common problems
  8. Need more help?
  9. Check if a cell contains text (case-insensitive)
  10. Find cells that contain text
  11. Check if a cell has any text in it
  12. Check if a cell matches specific text
  13. Check if part of a cell matches specific text
  14. Cell contains specific text
  15. Related functions
  16. Summary
  17. Generic formula
  18. Explanation
  19. SEARCH function (not case-sensitive)
  20. Wildcards
  21. FIND function (case-sensitive)
  22. If cell contains
  23. With hardcoded search string
  24. IF Excel Function
  25. What is IF Function in Excel?
  26. Syntax of the IF Excel Function
  27. How to Use IF Function in Excel?
  28. Example #1
  29. Example #2
  30. Example #3
  31. Example #4
  32. Example #5
  33. Guidelines for the Multiple IF Statements
  34. Frequently Asked Question
  35. IF Excel Function Video
  36. Recommended Articles

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

The condition you want to test.

The value that you want returned if the result of logical_test is TRUE.

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

=IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

B2,C2-B2,»»)» loading=»lazy»>

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

What went wrong

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

The condition you want to test.

The value that you want returned if the result of logical_test is TRUE.

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

=IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

B2,C2-B2,»»)» loading=»lazy»>

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

What went wrong

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

Check if a cell contains text (case-insensitive)

Let’s say you want to ensure that a column contains text, not numbers. Or, perhapsyou want to find all orders that correspond to a specific salesperson. If you have no concern for upper- or lowercase text, there are several ways to check if a cell contains text.

You can also use a filter to find text. For more information, see Filter data.

Find cells that contain text

Follow these steps to locate cells containing specific text:

Select the range of cells that you want to search.

To search the entire worksheet, click any cell.

On the Home tab, in the Editing group, click Find & Select, and then click Find.

In the Find what box, enter the text—or numbers—that you need to find. Or, choose a recent search from the Find what drop-down box.

Note: You can use wildcard characters in your search criteria.

To specify a format for your search, click Format and make your selections in the Find Format popup window.

Click Options to further define your search. For example, you can search for all of the cells that contain the same kind of data, such as formulas.

In the Within box, you can select Sheet or Workbook to search a worksheet or an entire workbook.

Click Find All or Find Next.

Find All lists every occurrence of the item that you need to find, and allows you to make a cell active by selecting a specific occurrence. You can sort the results of a Find All search by clicking a header.

Note: To cancel a search in progress, press ESC.

Check if a cell has any text in it

To do this task, use the ISTEXT function.

Check if a cell matches specific text

Use the IF function to return results for the condition that you specify.

Check if part of a cell matches specific text

To do this task, use the IF, SEARCH, and ISNUMBER functions.

Note: The SEARCH function is case-insensitive.

Источник

Cell contains specific text

Summary

To check if a cell contains specific text (i.e. a substring), you can use the SEARCH function together with the ISNUMBER function. In the example shown, the formula in D5 is:

This formula returns TRUE if the substring is found, and FALSE if not. Note the SEARCH function is not case-sensitive. See below for a case-sensitive formula.

Generic formula

Explanation

In this example, the goal is to test a value in a cell to see if it contains a specific substring. Excel contains two functions designed to check the occurrence of one text string inside another: the SEARCH function and the FIND function. Both functions return the position of the substring if found as a number, and a #VALUE! error if the substring is not found. The difference is that the SEARCH function supports wildcards but is not case-sensitive, while the FIND function is case-sensitive but does not support wildcards. The general approach with either function is to use the ISNUMBER function to check for a numeric result (a match) and return TRUE or FALSE.

SEARCH function (not case-sensitive)

The SEARCH function is designed to look inside a text string for a specific substring. If SEARCH finds the substring, it returns a position of the substring in the text as a number. If the substring is not found, SEARCH returns a #VALUE error. For example:

To force a TRUE or FALSE result, we use the ISNUMBER function. ISNUMBER returns TRUE for numeric values and FALSE for anything else. So, if SEARCH finds the substring, it returns the position as a number, and ISNUMBER returns TRUE:

If SEARCH doesn’t find the substring, it returns an error, which causes the ISNUMBER to return FALSE.

Wildcards

Although SEARCH is not case-sensitive, it does support wildcards (*?

). For example, the question mark (?) wildcard matches any one character. The formula below looks for a 3-character substring beginning with «x» and ending in «y»:

The asterisk (*) wildcard matches zero or more characters. This wildcard is not as useful in the SEARCH function because SEARCH already looks for a substring. For example, it might seem like the following formula will test for a value that ends with «z»:

However, because SEARCH automatically looks for a substring, the following formulas all return 1 as a result, even though the text in the first formula is the only text that ends with «z»:

This means the asterisk (*) is not a reliable way to test for «ends with». However, you an use the the asterisk (*) wildcard like this:

Here we are looking for «x», «2», and «b» in that order, with any number of characters in between. Finally, you can use the tilde (

) as an escape character to indicate that the next character is a literal like this:

The above formulas use SEARCH to find a literal asterisk (*), question mark (?) , and tilde (

FIND function (case-sensitive)

Like the SEARCH function, the FIND function returns the position of a substring in text as a number, and an error if the substring is not found. However, unlike the SEARCH function, the FIND function respects case:

To make a case-sensitive version of the formula, just replace the SEARCH function with the FIND function in the formula above:

The result is a case-sensitive search:

If cell contains

To return a custom result when a cell contains specific text, add the IF function like this:

Instead of returning TRUE or FALSE, the formula above will return «Yes» if substring is found and «No» if not.

With hardcoded search string

To test for a hardcoded substring, enclose the text in double quotes («»). For example, to check A1 for the text «apple» use:

Источник

IF Excel Function

What is IF Function in Excel?

IF function in Excel evaluates whether a given condition is met and returns a value depending on whether the result is “true” or “false”. It is a conditional function of Excel, which returns the result based on the fulfillment or non-fulfillment of the given criteria.

For example, the IF formula in Excel can be applied as follows:

“=IF(condition A,“value B”,“value C”)”

The IF excel function returns “value B” if condition A is met and returns “value C” if condition A is not met.

It is often used to make logical interpretations which help in decision-making.

Table of contents

Syntax of the IF Excel Function

The syntax of the IF function is shown in the following image:

The IF excel function accepts the following arguments:

  • Logical_test: It refers to the condition to be evaluated. The condition can be a value or a logical expression.
  • Value_if_true: It is the value returned as a result when the condition is “true”.
  • Value_if_false: It is the value returned as a result when the condition is “false”.

In the formula, the “logical_test” is a required argument, whereas the “value_if_true” and “value_if_false” are optional arguments.

Operator Meaning
= Equal to
> Greater than
>= Greater than or equal to
Not equal to

How to Use IF Function in Excel?

Let us understand the working of the IF function with the help of the following examples in Excel.

Example #1

If there is no oxygen on a planet, life is impossible. If oxygen is available on a planet, then life is possible. The following table shows a list of planets in column A and the information on the availability of oxygen in column B. We have to find the planets where life is possible, based on the condition of oxygen availability.

Let us apply the IF formula to cell C2 to find out whether life is possible on the planets listed in the table.

The IF formula is stated as follows:

“=IF(B2=“Yes”, “Life is Possible”, “Life is Not Possible”)

The succeeding image shows the IF formula applied to cell C2.

The subsequent image shows how the IF formula is applied to the range of cells C2:C5.

Drag the cells to view the output of all the planets.

The output in the below worksheet shows life is possible on the planet Earth.

Flow Chart of Generic IF Excel Function

The IF Function Flow Chart for Mars (Example #1)

The flow of IF function flowchart for Jupiter and Venus is the same as the IF function flowchart for Mars (Example #1).

The IF Function Flow Chart for Earth

Hence, the IF excel function allows making logical comparisons between values. The modus operandi of the IF function is stated as: If something is true, then do something; otherwise, do something else.

Example #2

The following table shows a list of years. We want to find out if the given year is a leap year or not.

A leap year has 366 days; the extra day is the 29th of February. The criteria for a leap year are stated as follows:

  1. The year will be exactly divisible by 4 and not exactly be divisible by 100 or
  2. The year will be exactly divisible by 400.

In this example, we will use the IF function along with the AND, OR, and MOD functions to find the leap years.

We use the MOD function to find a remainder after a dividend is divided by a divisor.

We will apply the MOD function to the conditions as follows:

If MOD(year,4)=0 and MOD(year,100)<>(is not equal to) 0, then the year is a leap year.

If MOD(year,400)=0, then the year is a leap year; otherwise, the year is not a leap year.

The IF formula is stated as follows:

“=IF(OR(AND((MOD(year,4)=0),(MOD(year,100)<>0)),(MOD(year,400)=0)),“Leap Year”, “Not A Leap Year”)”

The argument “year” refers to a reference value.

The following images show the output of the IF formula applied in the range of cells.

The following image shows how the IF formula is applied to the range of cells B2:B18.

The succeeding table shows the years 1960, 2028, and 2148 as leap years and the remaining as non-leap years.

The result of the IF excel formula is displayed for the range of cells B2:B18 in the following image.

Example #3

The succeeding table shows a list of drivers and the directions they undertook to reach the destination. It is preceded by an image of the road intersection explaining the turns taken by the drivers and their destinations. The right turn leads to town B, and the left turn leads to town C. Identify the driver’s destination to town B and town C.

Road Intersection Image

Let us apply the IF excel function to find the destination. Here, the condition is mentioned as follows:

  • If the driver turns right, he/she reaches town B.
  • If the driver turns left, he/she reaches town C.

We use the following IF formula to find the destination:

“=IF(B2=“Left”, “Town C”, “Town B”)”

The succeeding image shows the output of the IF formula applied to cell C2.

Drag the cells to use the formula in the range C2:C11. Finally, we get the destinations of each driver for their turning movements.

The below image displays the IF formula applied to the range.

The output of the IF formula and the destinations are displayed in the succeeding image.

The result shows that six drivers reached town C, and the remaining four have reached town B.

Example #4

The following table shows a list of items and their inventory levels. We want to check if the specific item is available in the inventory or not using the IF function.

Let us list the name of items in column A and the number of items in column B. The list of data to be validated for the entire items list is shown in the cell E2 of the below image.

The VLOOKUP function looks up the values referring to the number of items, and the IF function will check whether the item number is greater than zero or not.

We will apply the following IF formula in the F2 cell:

“=IF(VLOOKUP(E2,A2:B11,2,0)=0, “Item Not Available”,“Item Available”)”

If the lookup value of an item is equal to 0, then the item is not available; else, the item is available.

The succeeding image shows the result of the IF formula in the cell F2.

Select “bat” in the E2 item cell to know whether the item is available or not in the inventory (as shown in the following image).

Example #5

The following table shows the list of students and their marks. The grade criteria are provided based on the marks obtained by the students. We want to find the grade of each student in the list.

We apply the Nested IF in Excel since we have multiple criteria to find and decide each student’s grade.

The Nesting of IF function uses the IF function inside another IF formula when multiple conditions are to be fulfilled.

The syntax of Nesting of IF function is stated as follows:

“=IF( condition1, value_if_true1, IF( condition2, value_if_true2, value_if_false2 ))”

The succeeding table represents the range of scores and the grades, respectively.

Let us apply the multiple IF conditions with AND function in the below-nested formula to find out the grade of the students:

“=IF((B2>=95),“A”,IF(AND(B2>=85,B2 =75,B2 =61,B2 =95

If the formula returns,

  • Value_if_true, execute: “A” (Grade A) else(comma) enter value_if_false
  • Value_if_false, then the formula finds another IF condition and enter IF condition

Second Logical Test: B2>=85(logical expression 1) and B2 =75(logical expression 1) and B2 =61(logical expression 1) and B2

The succeeding image shows the IF nested formula applied to the range.

The grades of the students are listed in the following table.

Guidelines for the Multiple IF Statements

The guidelines for the multiple IF statements are listed as follows:

  • Use nested IF function to a limited extent as multiple IF statements require a great deal of thought to be accurate.
  • Multiple IF statementsMultiple IF StatementsIn Excel, multiple IF conditions are IF statements that are contained within another IF statement. They are used to test multiple conditions at the same time and return distinct values. Additional IF statements can be included in the ‘value if true’ and ‘value if false’ arguments of a standard IF formula.read more require multiple parentheses (), which is often difficult to manage. Excel provides a way to check the color of each opening and closing parenthesis to avoid this situation. The last closing parenthesis color will always be black, denoting the end of the formula statement.
  • Whenever we pass a string value for the arguments “value_if_true” and “value_if_false” or test a reference against a string value, enclose the string value in double quotes. Passing a string value without quotes will result in “#NAME?” error.

Frequently Asked Question

The Excel IF function is a logical function that checks the given criteria and returns one value for a “true” and another value for a “false” result.

The syntax of the IF function is stated as follows:
“=IF(logical_test, [value_if_true], [value_if_false])”

The arguments are as follows:
1. Logical_test – It refers to a value or condition that is tested.
2. Value_if_true – It is the value returned when the condition logical_test is “true.”
3. Value_if_false – It is the value returned when the condition logical_test is “false.”

The “logical_test” is a required argument, whereas the “value_if_true” and “value_if_false” are optional arguments.

The IF Excel statement for multiple conditions is created by using multiple IF functions in a single formula.

The syntax of IF function with multiple conditions is stated as follows:

“=IF (condition 1_“true”, do something, IF (condition 2_“true”, do something, IF (condition 3_ “true”, do something, else do something)))”

On checking a formula, if it finds an error, it returns another value specified by the user. Else it returns the result of the formula.

The syntax is stated as follows:
“=IFERROR(value, value_if_error)”
Where,
• Value – It refers to the value to be tested.
• Value_if_error – It refers to the value to be returned if the formula returns an error.
Both the arguments are the required arguments.

IF Excel Function Video

Recommended Articles

This has been a guide to the IF function in Excel. Here we discuss how to use the IF function along with examples and downloadable templates. You may also look at these useful functions –

Источник

Excel has a number of formulas that help you use your data in useful ways. For example, you can get an output based on whether or not a cell meets certain specifications. Right now, we’ll focus on a function called “if cell contains, then”. Let’s look at an example.

Jump To Specific Section:

  1. Explanation: If Cell Contains
  2. If cell contains any value, then return a value
  3. If cell contains text/number, then return a value
  4. If cell contains specific text, then return a value
  5. If cell contains specific text, then return a value (case-sensitive)
  6. If cell does not contain specific text, then return a value
  7. If cell contains one of many text strings, then return a value
  8. If cell contains several of many text strings, then return a value

Excel Formula: If cell contains

Generic formula 

=IF(ISNUMBER(SEARCH("abc",A1)),A1,"")

Summary 

To test for cells that contain certain text, you can use a formula that uses the IF function together with the SEARCH and ISNUMBER functions.  In the example shown, the formula in C5 is:

=IF(ISNUMBER(SEARCH("abc",B5)),B5,"")

If you want to check whether or not the A1 cell contains the text “Example”, you can run a formula that will output “Yes” or “No” in the B1 cell. There are a number of different ways you can put these formulas to use. At the time of writing, Excel is able to return the following variations:

  • If cell contains any value
  • If cell contains text
  • If cell contains number
  • If cell contains specific text
  • If cell contains certain text string
  • If cell contains one of many text strings
  • If cell contains several strings

Using these scenarios, you’re able to check if a cell contains text, value, and more. 

Explanation: If Cell Contains

One limitation of the IF function is that it does not support Excel wildcards like «?» and «*». This simply means you can’t use IF by itself to test for text that may appear anywhere in a cell.

One solution is a formula that uses the IF function together with the SEARCH and ISNUMBER functions. For example, if you have a list of email addresses, and want to extract those that contain «ABC», the formula to use is this:

=IF(ISNUMBER(SEARCH("abc",B5)),B5,""). Assuming cells run to B5

If «abc» is found anywhere in a cell B5, IF will return that value. If not, IF will return an empty string («»). This formula’s logical test is this bit:

ISNUMBER(SEARCH("abc",B5))


Read article: Excel efficiency: 11 Excel Formulas To Increase Your Productivity

Using “if cell contains” formulas in Excel

The guides below were written using the latest Microsoft Excel 2019 for Windows 10. Some steps may vary if you’re using a different version or platform. Contact our experts if you need any further assistance.

1. If cell contains any value, then return a value

This scenario allows you to return values based on whether or not a cell contains any value at all. For example, we’ll be checking whether or not the A1 cell is blank or not, and then return a value depending on the result.

  • Select the output cell, and use the following formula: =IF(cell<>»», value_to_return, «»).
  • For our example, the cell we want to check is A2, and the return value will be No. In this scenario, you’d change the formula to =IF(A2<>»», «No», «»)
  • Since the A2 cell isn’t blank, the formula will return “No” in the output cell. If the cell you’re checking is blank, the output cell will also remain blank.

2. If cell contains text/number, then return a value

With the formula below, you can return a specific value if the target cell contains any text or number. The formula will ignore the opposite data types.

Check for text

  • To check if a cell contains text, select the output cell, and use the following formula: =IF(ISTEXT(cell), value_to_return, «»).
  • For our example, the cell we want to check is A2, and the return value will be Yes. In this scenario, you’d change the formula to =IF(ISTEXT(A2), «Yes», «»)
    check for txt
  • Because the A2 cell does contain text and not a number or date, the formula will return “Yes” into the output cell.

Check for a number or date

  • To check if a cell contains a number or date, select the output cell, and use the following formula: =IF(ISNUMBER(cell), value_to_return, «»).
  • For our example, the cell we want to check is D2, and the return value will be Yes. In this scenario, you’d change the formula to =IF(ISNUMBER(D2), «Yes», «»)
    check for number or date
  • Because the D2 cell does contain a number and not text, the formula will return “Yes” into the output cell.

3. If cell contains specific text, then return a value

To find a cell that contains specific text, use the formula below.

  • Select the output cell, and use the following formula: =IF(cell=»text», value_to_return, «»).
  • For our example, the cell we want to check is A2, the text we’re looking for is “example”, and the return value will be Yes. In this scenario, you’d change the formula to =IF(A2=»example», «Yes», «»)
    If cell contains specific text, then return a value
  • Because the A2 cell does consist of the text “example”, the formula will return “Yes” into the output cell.

4. If cell contains specific text, then return a value (case-sensitive)

To find a cell that contains specific text, use the formula below. This version is case-sensitive, meaning that only cells with an exact match will return the specified value.

  • Select the output cell, and use the following formula: =IF(EXACT(cell,»case_sensitive_text»), «value_to_return», «»).
  • For our example, the cell we want to check is A2, the text we’re looking for is “EXAMPLE”, and the return value will be Yes. In this scenario, you’d change the formula to =IF(EXACT(A2,»EXAMPLE»), «Yes», «»).
  • Because the A2 cell does consist of the text “EXAMPLE” with the matching case, the formula will return “Yes” into the output cell.

5. If cell does not contain specific text, then return a value

The opposite version of the previous section. If you want to find cells that don’t contain a specific text, use this formula.

  • Select the output cell, and use the following formula: =IF(cell=»text», «», «value_to_return»).
  • For our example, the cell we want to check is A2, the text we’re looking for is “example”, and the return value will be No. In this scenario, you’d change the formula to =IF(A2=»example», «», «No»).
    If cell contains specific text, then return a value (case-sensitive)
  • Because the A2 cell does consist of the text “example”, the formula will return a blank cell. On the other hand, other cells return “No” into the output cell.

6. If cell contains one of many text strings, then return a value

This formula should be used if you’re looking to identify cells that contain at least one of many words you’re searching for.

  • Select the output cell, and use the following formula: =IF(OR(ISNUMBER(SEARCH(«string1», cell)), ISNUMBER(SEARCH(«string2», cell))), value_to_return, «»).
  • For our example, the cell we want to check is A2. We’re looking for either “tshirt” or “hoodie”, and the return value will be Valid. In this scenario, you’d change the formula to =IF(OR(ISNUMBER(SEARCH(«tshirt»,A2)),ISNUMBER(SEARCH(«hoodie»,A2))),»Valid «,»»).
    =IF(OR(ISNUMBER(SEARCH("tshirt",A2)),ISNUMBER(SEARCH("hoodie",A2))),"Valid ","").
  • Because the A2 cell does contain one of the text values we searched for, the formula will return “Valid” into the output cell.

To extend the formula to more search terms, simply modify it by adding more strings using ISNUMBER(SEARCH(«string», cell)).

7. If cell contains several of many text strings, then return a value

This formula should be used if you’re looking to identify cells that contain several of the many words you’re searching for. For example, if you’re searching for two terms, the cell needs to contain both of them in order to be validated.

  • Select the output cell, and use the following formula: =IF(AND(ISNUMBER(SEARCH(«string1»,cell)), ISNUMBER(SEARCH(«string2″,cell))), value_to_return,»»).
  • For our example, the cell we want to check is A2. We’re looking for “hoodie” and “black”, and the return value will be Valid. In this scenario, you’d change the formula to =IF(AND(ISNUMBER(SEARCH(«hoodie»,A2)),ISNUMBER(SEARCH(«black»,A2))),»Valid «,»»).
    =IF(AND(ISNUMBER(SEARCH("hoodie",A2)),ISNUMBER(SEARCH("black",A2))),"Valid ","").
  • Because the A2 cell does contain both of the text values we searched for, the formula will return “Valid” to the output cell.

Final thoughts

We hope this article was useful to you in learning how to use “if cell contains” formulas in Microsoft Excel. Now, you can check if any cells contain values, text, numbers, and more. This allows you to navigate, manipulate and analyze your data efficiently.

We’re glad you’re read the article up to here :) Thank you :)

You may also like

» How to use NPER Function in Excel
» How to Separate First and Last Name in Excel
» How to Calculate Break-Even Analysis in Excel

Понравилась статья? Поделить с друзьями:
  • If any cell contains value excel
  • If function excel for dates
  • Idioms with word feet
  • If and when in excel
  • Idioms with word change