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 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 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")
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 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.…
Содержание
- IF function
- Simple IF examples
- Common problems
- Need more help?
- How To Use “If Cell Contains” Formulas in Excel
- Excel Formula: If cell contains
- Explanation: If Cell Contains
- Using “if cell contains” formulas in Excel
- 1. If cell contains any value, then return a value
- 2. If cell contains text/number, then return a value
- Check for text
- Check for a number or date
- 3. If cell contains specific text, then return a value
- 4. If cell contains specific text, then return a value (case-sensitive)
- 5. If cell does not contain specific text, then return a value
- 6. If cell contains one of many text strings, then return a value
- 7. If cell contains several of many text strings, then return a value
- Final thoughts
- Before you go
- Excel IF function with text values
- 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
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.
Источник
How To Use “If Cell Contains” Formulas in Excel
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.
Excel Formula: If cell contains
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 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 «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:
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», «») .
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», «») .
- 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», «») .
- 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», «») .
- 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») .
- 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 «,»») .
- 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 «,»») .
- 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 🙂
Please share it on your socials. Someone else will benefit.
Before you go
If you need any further help with Excel, don’t hesitate to reach out to our customer service team, which is available 24/7 to assist you. Return to us for more informative articles all related to productivity and modern-day technology!
Would you like to receive promotions, deals, and discounts to get our products for the best price? Don’t forget to subscribe to our newsletter by entering your email address below! Receive the latest technology news in your inbox and be the first to read our tips to become more productive.
Источник
Excel IF function with text values
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”.
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.
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 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:
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.
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 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])
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
-
=IF(C2=”Yes”,1,2)
In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)
-
=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.
-
=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”)
-
=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).
-
=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.
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?
Getting IF Function to Work for Partial Text Match
In the dataset below, we want to write a formula in column B that will search the text in column A. Our formula will search the column A text for the text sequence “AT” and if found display “AT” in column B.
It doesn’t matter where the letters “AT” occur in the column A text, we need to see “AT” in the adjacent cell of column B. If the letters “AT” do not occur in the column A text, the formula in column B should display nothing.
Searching for Text with the IF Function
Let’s begin by selecting cell B5 and entering the following IF formula.
=IF(A5="*AT*","AT","")
Notice the formula returns nothing, even though the text in cell A5 contains the letter sequence “AT”.
The reason it fails is that Excel doesn’t work well when using wildcards directly after an equals sign in a formula.
Any function that uses an equals sign in a logical test does not like to use wildcards in this manner.
“But what about the SUMIFS function?”, I hear you saying.
If you examine a SUMIFS function, the wildcards don’t come directly after the equals sign; they instead come after an argument. As an example:
=SUMIFS($C$4:$C$18,$A$4:$A$18,"*AT*")
The wildcard usage does not appear directly after an equals sign.
SEARCH Function to the Rescue
The first thing we need to understand is the syntax of the SEARCH function. The syntax is as follows:
SEARCH(find_text, within_text, [start_num])
- find_text – is a required argument that defines the text you are searching for.
- within_text – is a required argument that defines the text in which you want to search for the value defined in the find_text
- Start_num – is an option argument that defines the character number/position in the within_text argument you wish to start searching. If omitted, the default start character position is 1 (the first character on the left of the text.)
To see if the search function works properly on its own, lets perform a simple test with the following formula.
=SEARCH("AT",A5)
We are returned a character position which the letters “AT” were discovered by the SEARCH function. The first SEARCH found the letters “AT” beginning in the 1st character position of the text. The next discovery was in the 5th character position, and the last discovery was in the 4th character position.
The “#VALUE!” responses are the SEARCH function’s way of letting us know that the letters “AT” were not found in the search text.
We can use this new information to determine if the text “AT” exists in the companion text strings. If we see any number as a response, we know “AT” exists in the text string. If we receive an error response, we know the text “AT” does not exist in the text string.
NOTE: The SEARCH function is NOT case-sensitive. A search for the letters “AT” would find “AT”, “At”, “aT”, and “at”. If you wish to search for text and discriminate between different cases (case-sensitive), use the FIND function. The FIND function works the same as SEARCH, but with the added behavior of case-sensitivity.
Turning Numbers into Decisions
An interesting function in Excel is the ISNUMBER function. The purpose of the ISNUMBER function is to return “True” if something is a number and “False” if something is not a number. The syntax is as follows:
ISNUMBER(value)
- value – is a required argument that defines the data you are examining. The value can refer to a cell, a formula, or a name that refers to a cell, formula, or value.
Let’s add the ISNUMBER function to the logic of our previous SEARCH function.
=ISNUMBER(SEARCH("AT",A5))
Any cell that contained a numeric response is now reading “True” and any cell that contained an error is now reading “False”.
We are now able to use the ISNUMBER/SEARCH functions as our wildcard statement in the original IF function.
=IF(ISNUMBER(SEARCH("AT",A5)),"AT","")
This is a great way to perform logical tests in functions that do not allow for wildcards.
Let’s see another scenario
Suppose we want to search for two different sets of text (“AT” or “DE”) and return the word “Europe” if either of these text strings are discovered in the searched text. We will combine the original formula with an OR function to search for multiple text strings.
=IF(OR(ISNUMBER(SEARCH("AT",A5)),ISNUMBER(SEARCH("DE",A5))),
"Europe","")
Practice Workbook
Feel free to Download the Workbook HERE.
Published on: June 2, 2019
Last modified: March 29, 2023
Leila Gharani
I’m a 5x Microsoft MVP with over 15 years of experience implementing and professionals on Management Information Systems of different sizes and nature.
My background is Masters in Economics, Economist, Consultant, Oracle HFM Accounting Systems Expert, SAP BW Project Manager. My passion is teaching, experimenting and sharing. I am also addicted to learning and enjoy taking online courses on a variety of topics.
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:
- Explanation: If Cell Contains
- If cell contains any value, then return a value
- If cell contains text/number, then return a value
- If cell contains specific text, then return a value
- If cell contains specific text, then return a value (case-sensitive)
- If cell does not contain specific text, then return a value
- If cell contains one of many text strings, then return a value
- 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», «»).
- 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», «»).
- 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», «»).
- 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»).
- 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 «,»»).
- 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 «,»»).
- 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
Posted by Chris Rock on October 24, 2001 1:53 PM
Is it possible to write an IF statement that looks at a string of text, and will perform an action if the string CONTAINS a certain word?
For example. IF this statement in cell A1 contains the word «dog», write «dog». Otherwise, write nothing.
«I went to the pet store and I bought some dog food.»
I can’t put =IF(A1=dog,»dog»,»») because A1 doesn’t EQUAL «dog», it CONTAINS «dog».
Or is there a better way to do this?
Thanks.
Posted by Mark W. on October 24, 2001 1:56 PM
=IF(ISNUMBER(SEARCH(«*dog*»,A1)),»dog»,»»)
Posted by Chris Rock on October 24, 2001 2:00 PM
THANK YOU!!! I wish I’d thought of that!
Posted by Mark W. on October 24, 2001 2:02 PM
BTW, you can get by without wildcards («*») too…
=IF(ISNUMBER(SEARCH(«dog»,A1)),»dog»,»»)
Posted by Kevin on October 24, 2001 4:24 PM
I think the easiest way to obtain the results you are looking for would be this:
Note the column header must = F10
=IF($F10=J$9,+F10)
To check if a cell contains specific text, use ISNUMBER and SEARCH in Excel. There’s no CONTAINS function in Excel.
1. To find the position of a substring in a text string, use the SEARCH function.
Explanation: «duck» found at position 10, «donkey» found at position 1, cell A4 does not contain the word «horse» and «goat» found at position 12.
2. Add the ISNUMBER function. The ISNUMBER function returns TRUE if a cell contains a number, and FALSE if not.
Explanation: cell A2 contains the word «duck», cell A3 contains the word «donkey», cell A4 does not contain the word «horse» and cell A5 contains the word «goat».
3. You can also check if a cell contains specific text, without displaying the substring. Make sure to enclose the substring in double quotation marks.
4. To perform a case-sensitive search, replace the SEARCH function with the FIND function.
Explanation: the formula in cell C3 returns FALSE now. Cell A3 does not contain the word «donkey» but contains the word «Donkey».
5. Add the IF function. The formula below (case-insensitive) returns «Found» if a cell contains specific text, and «Not Found» if not.
6. You can also use IF and COUNTIF in Excel to check if a cell contains specific text. However, the COUNTIF function is always case-insensitive.
Explanation: the formula in cell C2 reduces to =IF(COUNTIF(A2,»*duck*»),»Found»,»Not Found»). An asterisk (*) matches a series of zero or more characters. Visit our page about the COUNTIF function to learn all you need to know about this powerful function.
The logical IF statement in Excel is used for the recording of certain conditions. It compares the number and / or text, function, etc. of the formula when the values correspond to the set parameters, and then there is one record, when do not respond — another.
Logic functions — it is a very simple and effective tool that is often used in practice. Let us consider it in details by examples.
The syntax of the function «IF» with one condition
The operation syntax in Excel is the structure of the functions necessary for its operation data.
=IF(boolean;value_if_TRUE;value_if_FALSE)
Let us consider the function syntax:
- Boolean – what the operator checks (text or numeric data cell).
- Value_if_TRUE – what will appear in the cell when the text or numbers correspond to a predetermined condition (true).
- Value_if_FALSE – what appears in the box when the text or the number does not meet the predetermined condition (false).
Example:
Logical IF functions.
The operator checks the A1 cell and compares it to 20. This is a «Boolean». When the contents of the column is more than 20, there is a true legend «greater 20». In the other case it’s «less or equal 20».
Attention! The words in the formula need to be quoted. For Excel to understand that you want to display text values.
Here is one more example. To gain admission to the exam, a group of students must successfully pass a test. The results are listed in a table with columns: a list of students, a credit, an exam.
The statement IF should check not the digital data type but the text. Therefore, we prescribed in the formula В2= «done» We take the quotes for the program to recognize the text correctly.
The function IF in Excel with multiple conditions
Usually one condition for the logic function is not enough. If you need to consider several options for decision-making, spread operators’ IF into each other. Thus, we get several functions IF in Excel.
The syntax is as follows:
Here the operator checks the two parameters. If the first condition is true, the formula returns the first argument is the truth. False — the operator checks the second condition.
Examples of a few conditions of the function IF in Excel:
It’s a table for the analysis of the progress. The student received 5 points:
- А – excellent;
- В – above average or superior work;
- C – satisfactory;
- D – a passing grade;
- E – completely unsatisfactory.
IF statement checks two conditions: the equality of value in the cells.
In this example, we have added a third condition, which implies the presence of another report card and «twos». The principle of the operator is the same.
Enhanced functionality with the help of the operators «AND» and «OR»
When you need to check out a few of the true conditions you use the function И. The point is: IF A = 1 AND A = 2 THEN meaning в ELSE meaning с.
OR function checks the condition 1 or condition 2. As soon as at least one condition is true, the result is true. The point is: IF A = 1 OR A = 2 THEN value B ELSE value C.
Functions AND & OR can check up to 30 conditions.
An example of using the operator AND:
It’s the example of using the logical operator OR.
How to compare data in two tables
Users often need to compare the two spreadsheets in an Excel to match. Examples of the «life»: compare the prices of goods in different bringing, to compare balances (accounting reports) in a few months, the progress of pupils (students) of different classes, in different quarters, etc.
To compare the two tables in Excel, you can use the COUNTIFS statement. Consider the order of application functions.
For example, consider the two tables with the specifications of various food processors. We planned allocation of color differences. This problem in Excel solves the conditional formatting.
Baseline data (tables, which will work with):
Select the first table. Conditional Formatting — create a rule — use a formula to determine the formatted cells:
In the formula bar write: = COUNTIFS (comparable range; first cell of first table)=0. Comparing range is in the second table.
To drive the formula into the range, just select it first cell and the last. «= 0» means the search for the exact command (not approximate) values.
Choose the format and establish what changes in the cell formula in compliance. It’s better to do a color fill.
Select the second table. Conditional Formatting — create a rule — use the formula. Use the same operator (COUNTIFS). For the second table formula:
Download all examples in Excel
Now it is easy to compare the characteristics of the data in the table.