Содержание
- 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 Cell Contains Text
- If Cell Contains Text
- If Cell Contains Text Then TRUE
- If Cell Contains Partial Text
- Find for Case Sensitive Match:
- Search for Not Case Sensitive Match:
- If Range of Cells Contains Text
- If Cells Contains Text From List
- If Cell Contains Text Then Return a Value
- Excel if cell contains word then assign value
- Count If Cell Contains Text
- Count If Cell Contains Partial Text
- If Cell contains text from list then return value
- If Cell Contains Text Then SUM
- Sum If Cell Contains Partial Text
- VBA to check if Cell Contains Text
- If Cell Contains Partial Text VBA
- If Cell Contains Text Then VBA MsgBox
- Which function returns true if cell a1 contains text?
- Which function returns true if cell a1 contains text value?
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 Cell Contains Text
Excel If Cell Contains Text Then Formula helps you to return the output when a cell have any text or a specific text. You can check if a cell contains a some string or text and produce something in other cell. For Example you can check if a cell A1 contains text ‘example text’ and print Yes or No in Cell B1. Following are the example Formulas to check if Cell contains text then return some thing in a Cell.
If Cell Contains Text
Here are the Excel formulas to check if Cell contains specific text then return something. This will return if there is any string or any text in given Cell. We can use this simple approach to check if a cell contains text, specific text, string, any text using Excel If formula. We can use equals to operator(=) to compare the strings .
If Cell Contains Text Then TRUE
Following is the Excel formula to return True if a Cell contains Specif Text. You can check a cell if there is given string in the Cell and return True or False.
The formula will return true if it found the match, returns False of no match found.
If Cell Contains Partial Text
We can return Text If Cell Contains Partial Text. We use formula or VBA to Check Partial Text in a Cell.
Find for Case Sensitive Match:
We can check if a Cell Contains Partial Text then return something using Excel Formula. Following is a simple example to find the partial text in a given Cell. We can use if your want to make the criteria case sensitive.
- Here, Find Function returns the finding position of the given string
- Use Find function is Case Sensitive
- IsError Function check if Find Function returns Error, that means, string not found
Search for Not Case Sensitive Match:
We can use Search function to check if Cell Contains Partial Text. Search function useful if you want to make the checking criteria Not Case Sensitive.
If Range of Cells Contains Text
We can check for the strings in a range of cells. Here is the formula to find If Range of Cells Contains Text. We can use Count If Formula to check the excel if range of cells contains specific text and return Text.
- CountIf function counts the number of cells with given criteria
- We can use If function to return the required Text
- Formula displays the Text ‘Range Contains Text” if match found
- Returns “Text Not Found in the Given Range” if match not found in the specified range
If Cells Contains Text From List
Below formulas returns text If Cells Contains Text from given List. You can use based on your requirement.
VlookUp to Check If Cell Contains Text from a List:
We can use VlookUp function to match the text in the Given list of Cells. And return the corresponding values.
- Check if a List Contains Text:
=IF(ISERR(VLOOKUP(F1,A1:B21,2,FALSE)),”False:Not Contains”,”True: Text Found”) - Check if a List Contains Text and Return Corresponding Value:
=VLOOKUP(F1,A1:B21,2,FALSE) - Check if a List Contains Partial Text and Return its Value:
=VLOOKUP(“*”&F1&”*”,A1:B21,2,FALSE)
If Cell Contains Text Then Return a Value
We can return some value if cell contains some string. Here is the the the Excel formula to return a value if a Cell contains Text. You can check a cell if there is given string in the Cell and return some string or value in another column.
The formula will return true if it found the match, returns False of no match found. can
Excel if cell contains word then assign value
You can replace any word in the following formula to check if cell contains word then assign value.
Search function will check for a given word in the required cell and return it’s position. We can use If function to check if the value is greater than 0 and assign a given value (example: 1) in the cell. search function returns #Value if there is no match found in the cell, we can handle this using IFERROR function.
Count If Cell Contains Text
We can check If Cell Contains Text Then COUNT. Here is the Excel formula to Count if a Cell contains Text. You can count the number of cells containing specific text.
The formula will Sum the values in Column B if the cells of Column A contains the given text.
Count If Cell Contains Partial Text
We can count the cells based on partial match criteria. The following Excel formula Counts if a Cell contains Partial Text.
- We can use the CountIf Function to Count the Cells if they contains given String
- Wild-card operators helps to make the CountIf to check for the Partial String
- Put Your Text between two asterisk symbols (*YourText*) to make the criteria to find any where in the given Cell
- Add Asterisk symbol at end of your text (YourText*) to make the criteria to find your text beginning of given Cell
- Place Asterisk symbol at beginning of your text (*YourText) to make the criteria to find your text end of given Cell
If Cell contains text from list then return value
Here is the Excel Formula to check if cell contains text from list then return value. We can use COUNTIF and OR function to check the array of values in a Cell and return the given Value. Here is the formula to check the list in range D2:D5 and check in Cell A2 and return value in B2.
If Cell Contains Text Then SUM
Following is the Excel formula to Sum if a Cell contains Text. You can total the cell values if there is given string in the Cell. Here is the example to sum the column B values based on the values in another Column.
The formula will Sum the values in Column B if the cells of Column A contains the given text.
Sum If Cell Contains Partial Text
Use SumIfs function to Sum the cells based on partial match criteria. The following Excel formula Sums the Values if a Cell contains Partial Text.
- SUMIFS Function will Sum the Given Sum Range
- We can specify the Criteria Range, and wild-card expression to check for the Partial text
- Put Your Text between two asterisk symbols (*YourText*) to Sum the Cells if the criteria to find any where in the given Cell
- Add Asterisk symbol at end of your text (YourText*) to Sum the Cells if the criteria to find your text beginning of given Cell
- Place Asterisk symbol at beginning of your text (*YourText) to Sum the Cells if criteria to find your text end of given Cell
VBA to check if Cell Contains Text
Here is the VBA function to find If Cells Contains Text using Excel VBA Macros.
If Cell Contains Partial Text VBA
We can use VBA to check if Cell Contains Text and Return Value. Here is the simple VBA code match the partial text. Excel VBA if Cell contains partial text macros helps you to use in your procedures and functions.
- CheckIfCellContainsPartialText VBA Function returns true if Cell Contains Partial Text
- inStr Function will return the Match Position in the given string
If Cell Contains Text Then VBA MsgBox
Here is the simple VBA code to display message box if cell contains text. We can use inStr Function to search for the given string. And show the required message to the user.
- inStr Function will return the Match Position in the given string
- blnMatch is the Boolean variable becomes True when match string
- You can display the message to the user if a Range Contains Text
Which function returns true if cell a1 contains text?
You can use the Excel If function and Find function to return TRUE if Cell A1 Contains Text. Here is the formula to return True.
Which function returns true if cell a1 contains text value?
You can use the Excel If function with Find function to return TRUE if a Cell A1 Contains Text Value. Below is the formula to return True based on the text value.
Источник
I have an excel document I have to process regularly, while awaiting my company to build an automated process for this, and the issue we recently found is that the formula I’m using strips can’t return a result other than #VALUE! when the FIND formula fails to find the text I need it to.
the formula we currently have is:
=IF(FIND("-",M2,3),RIGHT(M2,2))
The cells this formula checks have states, & provinces in them which look like so «CA-ON» or «US-NV».
The problem is that regions for the UK don’t fillout as «UK-XX» it inputs the actual county for example «Essex» or «Merryside»
What I need the formula to do is, if it can’t find the hyphen(-) in the cell, then it should just take whatever value is there and write it in the cell the formula is in.
I should also mention that some of the cells are also blank, since this is an optional field. Is there anyway to run this formula where if it doesn’t find the «-» it just writes whats there?
Excel for Microsoft 365 Excel 2021 Excel 2019 Excel 2016 Excel 2013 Excel 2010 Excel 2007 More…Less
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.
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.
Excel If Cell Contains Text
Excel If Cell Contains Text Then Formula helps you to return the output when a cell have any text or a specific text. You can check if a cell contains a some string or text and produce something in other cell. For Example you can check if a cell A1 contains text ‘example text’ and print Yes or No in Cell B1. Following are the example Formulas to check if Cell contains text then return some thing in a Cell.
If Cell Contains Text
Here are the Excel formulas to check if Cell contains specific text then return something. This will return if there is any string or any text in given Cell. We can use this simple approach to check if a cell contains text, specific text, string, any text using Excel If formula. We can use equals to operator(=) to compare the strings .
If Cell Contains Text Then TRUE
Following is the Excel formula to return True if a Cell contains Specif Text. You can check a cell if there is given string in the Cell and return True or False.
The formula will return true if it found the match, returns False of no match found.
If Cell Contains Partial Text
We can return Text If Cell Contains Partial Text. We use formula or VBA to Check Partial Text in a Cell.
Find for Case Sensitive Match:
We can check if a Cell Contains Partial Text then return something using Excel Formula. Following is a simple example to find the partial text in a given Cell. We can use if your want to make the criteria case sensitive.
- Here, Find Function returns the finding position of the given string
- Use Find function is Case Sensitive
- IsError Function check if Find Function returns Error, that means, string not found
Search for Not Case Sensitive Match:
We can use Search function to check if Cell Contains Partial Text. Search function useful if you want to make the checking criteria Not Case Sensitive.
If Range of Cells Contains Text
We can check for the strings in a range of cells. Here is the formula to find If Range of Cells Contains Text. We can use Count If Formula to check the excel if range of cells contains specific text and return Text.
- CountIf function counts the number of cells with given criteria
- We can use If function to return the required Text
- Formula displays the Text ‘Range Contains Text” if match found
- Returns “Text Not Found in the Given Range” if match not found in the specified range
If Cells Contains Text From List
Below formulas returns text If Cells Contains Text from given List. You can use based on your requirement.
VlookUp to Check If Cell Contains Text from a List:
We can use VlookUp function to match the text in the Given list of Cells. And return the corresponding values.
- Check if a List Contains Text:
=IF(ISERR(VLOOKUP(F1,A1:B21,2,FALSE)),”False:Not Contains”,”True: Text Found”) - Check if a List Contains Text and Return Corresponding Value:
=VLOOKUP(F1,A1:B21,2,FALSE) - Check if a List Contains Partial Text and Return its Value:
=VLOOKUP(“*”&F1&”*”,A1:B21,2,FALSE)
If Cell Contains Text Then Return a Value
We can return some value if cell contains some string. Here is the the the Excel formula to return a value if a Cell contains Text. You can check a cell if there is given string in the Cell and return some string or value in another column.
The formula will return true if it found the match, returns False of no match found. can
Excel if cell contains word then assign value
You can replace any word in the following formula to check if cell contains word then assign value.
Search function will check for a given word in the required cell and return it’s position. We can use If function to check if the value is greater than 0 and assign a given value (example: 1) in the cell. search function returns #Value if there is no match found in the cell, we can handle this using IFERROR function.
Count If Cell Contains Text
We can check If Cell Contains Text Then COUNT. Here is the Excel formula to Count if a Cell contains Text. You can count the number of cells containing specific text.
The formula will Sum the values in Column B if the cells of Column A contains the given text.
Count If Cell Contains Partial Text
We can count the cells based on partial match criteria. The following Excel formula Counts if a Cell contains Partial Text.
- We can use the CountIf Function to Count the Cells if they contains given String
- Wild-card operators helps to make the CountIf to check for the Partial String
- Put Your Text between two asterisk symbols (*YourText*) to make the criteria to find any where in the given Cell
- Add Asterisk symbol at end of your text (YourText*) to make the criteria to find your text beginning of given Cell
- Place Asterisk symbol at beginning of your text (*YourText) to make the criteria to find your text end of given Cell
If Cell contains text from list then return value
Here is the Excel Formula to check if cell contains text from list then return value. We can use COUNTIF and OR function to check the array of values in a Cell and return the given Value. Here is the formula to check the list in range D2:D5 and check in Cell A2 and return value in B2.
If Cell Contains Text Then SUM
Following is the Excel formula to Sum if a Cell contains Text. You can total the cell values if there is given string in the Cell. Here is the example to sum the column B values based on the values in another Column.
The formula will Sum the values in Column B if the cells of Column A contains the given text.
Sum If Cell Contains Partial Text
Use SumIfs function to Sum the cells based on partial match criteria. The following Excel formula Sums the Values if a Cell contains Partial Text.
- SUMIFS Function will Sum the Given Sum Range
- We can specify the Criteria Range, and wild-card expression to check for the Partial text
- Put Your Text between two asterisk symbols (*YourText*) to Sum the Cells if the criteria to find any where in the given Cell
- Add Asterisk symbol at end of your text (YourText*) to Sum the Cells if the criteria to find your text beginning of given Cell
- Place Asterisk symbol at beginning of your text (*YourText) to Sum the Cells if criteria to find your text end of given Cell
VBA to check if Cell Contains Text
Here is the VBA function to find If Cells Contains Text using Excel VBA Macros.
If Cell Contains Partial Text VBA
We can use VBA to check if Cell Contains Text and Return Value. Here is the simple VBA code match the partial text. Excel VBA if Cell contains partial text macros helps you to use in your procedures and functions.
MsgBox CheckIfCellContainsPartialText(Cells(2, 1), “Region 1”)
End Sub
Function CheckIfCellContainsPartialText(ByVal cell As Range, ByVal strText As String) As Boolean
If InStr(1, cell.Value, strText) > 0 Then CheckIfCellContainsPartialText = True
End Function
- CheckIfCellContainsPartialText VBA Function returns true if Cell Contains Partial Text
- inStr Function will return the Match Position in the given string
If Cell Contains Text Then VBA MsgBox
Here is the simple VBA code to display message box if cell contains text. We can use inStr Function to search for the given string. And show the required message to the user.
If InStr(1, Cells(2, 1), “Region 3”) > 0 Then blnMatch = True
If blnMatch = True Then MsgBox “Cell Contains Text”
End Sub
- inStr Function will return the Match Position in the given string
- blnMatch is the Boolean variable becomes True when match string
- You can display the message to the user if a Range Contains Text
Which function returns true if cell a1 contains text?
You can use the Excel If function and Find function to return TRUE if Cell A1 Contains Text. Here is the formula to return True.
Which function returns true if cell a1 contains text value?
You can use the Excel If function with Find function to return TRUE if a Cell A1 Contains Text Value. Below is the formula to return True based on the text value.
Share This Story, Choose Your Platform!
7 Comments
-
Meghana
December 27, 2019 at 1:42 pm — ReplyHi Sir,Thank you for the great explanation, covers everything and helps use create formulas if cell contains text values.
Many thanks! Meghana!!
-
Max
December 27, 2019 at 4:44 pm — ReplyPerfect! Very Simple and Clear explanation. Thanks!!
-
Mike Song
August 29, 2022 at 2:45 pm — ReplyI tried this exact formula and it did not work.
-
Theresa A Harding
October 18, 2022 at 9:51 pm — Reply -
Marko
November 3, 2022 at 9:21 pm — ReplyHi
Is possible to sum all WA11?
(A1) WA11 4
(A2) AdBlue 1, WA11 223
(A3) AdBlue 3, WA11 32, shift 4
… and everything is in one column.
Thanks you very much for your help.
Sincerely Marko
-
Mike
December 9, 2022 at 9:59 pm — ReplyThank you for the help. The formula =OR(COUNTIF(M40,”*”&Vendors&”*”)) will give “TRUE” when some part of M40 contains a vendor from “Vendors” list. But how do I get Excel to tell which vendor it found in the M40 cell?
-
PNRao
December 18, 2022 at 6:05 am — ReplyPlease describe your question more elaborately.
Thanks!
-
© Copyright 2012 – 2020 | Excelx.com | All Rights Reserved
Page load link
In this article, we will learn How to look up cells having certain text and return the Certain Text in Excel.
Scenario :
Identify particular text in a cell or different word in given cells. For example finding the department ID from a database. I think you must have thought to do it manually but time constraint. You are here at the right place to learn How to check if a cell contains specific text.
Generic formula:
The text you are looking for can either be exact or case insensitive. Case insensitive means formula looks for AG can return ag, Ag, AG or aG.
Case insensitive formula:
=ISNUMBER(SEARCH(find_text,within_text)
find_text : text to find
within_text : to find in text
Case sensitive formula:
=ISNUMBER(FIND(find_text,within_text)
find_text : text to find
within_text : to find in text
Note:
The above formulas will return True or False. Use the IF function with formula to return YES or NO. Use the below formula to get the certain required result format.
Case insensitive formula:
=IF(ISNUMBER(SEARCH(find_text,within_text)),»value_if_true»,value_if_false)
find_text : text to find
within_text : to find in text
Case sensitive formula:
=IF(ISNUMBER(FIND(find_text,within_text)),»value_if_true»,value_if_false)
find_text : text to find
within_text : to find in text
Note: In The above mentioned formula you can input values like YES/NO or Found/Notfound.
Example :
All of these might be confusing to understand. Let’s understand how to use the function using an example. Here we have some employees to look up by the given department Id. Employee id has name, department id and particular id. Here lookup text is in column D and within text is in Column C.
Use the formula:
As you can see the formula finds AB when you looked for
AB using the Search function. Copy the formula to the rest of the cells using the Ctrl + D or dragging it down from the right bottom (tiny box) of the applied cell.
As you can see we found all the given department id employees using the above method. Now we will check if all cells contain specific text.
Another Example: (Case Sensitive)
Here we have been given a list of Employee Id information in column A and the look up department is «XG». Here we need to find the department «XG» in all cells. «XG» must be exact as there are two different departments that go by «Xg». So check only «XG» in all cells and return «Yes» if found and return «No» If not.
Use the formula:
As you can see First employee doesn’t belong to «XG» so the formula returns «No» using the FIND function. Copy the formula to the rest of the cells using the Ctrl + D or dragging it down from the right bottom (tiny box) of the applied cell.
As you can see there is only one employee in «XG» department. This formula is useful wherever the database contains multiple information of a row in one cell.
Check if cell Matches multiple text
In the above example we lookup one given text in cells. If we have multiple texts then we use the SUMPRODUCT function, This formula returns TRUE/FALSE as per the value found/ Not found.
Use the formula:
=SUMPRODUCT(—ISNUMBER(SEARCH(,A1)))>0
Learn more about this formula. Follow this link How to Check if a string contains one of many texts in Excel.
Here are all the observational notes using the above explained formulas in Excel
Notes :
- Use the «find_text» in quotes when using hard coded values. Or else use cell reference as explained in the first example.
- SEARCH is case insensitive function whereas FIND is the case Sensitive dunction.
- Use the IF function, if you want to get the result in required forms like YES/NO or Found/Notfound.
Hope this article about How to lookup cells having certain text and returns the Certain Text in Excel is explanatory. Find more articles on calculating values and related Excel formulas here. If you liked our blogs, share it with your friends on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write to us at info@exceltip.com.
Related Articles :
Searching a String for a Specific Substring in Excel : Find cells if cell contains given word in Excel using the FIND or SEARCH function.
Highlight cells that contain specific text : Highlight cells if cell contains given word in Excel using the formula under Conditional formatting
How to Check if a string contains one of many texts in Excel : lookup cells if cell contains from given multiple words in Excel using the FIND or SEARCH function.
Count Cells that contain specific text : Count number of cells if cell contains given text using one formula in Excel.
How to lookup cells having certain text and returns the Certain Text in Excel : find cells if cell contains certain text and returns required results using the IF function in Excel.
Popular Articles :
How to use the IF Function in Excel : The IF statement in Excel checks the condition and returns a specific value if the condition is TRUE or returns another specific value if FALSE.
How to use the VLOOKUP Function in Excel : This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.
How to use the SUMIF Function in Excel : This is another dashboard essential function. This helps you sum up values on specific conditions.
How to use the COUNTIF Function in Excel : Count values with conditions using this amazing function. You don’t need to filter your data to count specific values. Countif function is essential to prepare your dashboard.
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
Question: What formula tells you if A1 contains the text «apple»?
This is a surprisingly tricky problem in Excel. The «obvious» answer is to use the FIND function to «look» for the text, like this:
=FIND("apple",A1)
Then, if you want a TRUE/FALSE result, add the IF function:
=IF(FIND("apple",A1),TRUE)
This works great if «apple» is found – FIND returns a number to indicate the position, and IF calls it good and returns TRUE.
But FIND has an annoying quirk – if it doesn’t find «apple», it returns the #VALUE error. This means that the formula above doesn’t return FALSE when text isn’t found, it returns #VALUE:
FIND returns the position of the text (if found), but #VALUE if not found.
Unfortunately, this error appears even if we wrap the FIND function in the IF function.
Grrrr. Nobody likes to see errors in their spreadsheets.
(There may be some good reason for this, but returning zero would be much nicer.)
What about the SEARCH function, which also locates the position of text? Unlike FIND, SEARCH supports wildcards, and is not case-sensitive. Maybe SEARCH returns FALSE or zero if the text isn’t found?
Nope. SEARCH also returns #VALUE when the text isn’t found.
So, what to do? Well, in a classic, counter-intuitive Excel move, you can trap the #VALUE error with the ISNUMBER function, like this:
=ISNUMBER(FIND("apple",A1))
Now ISNUMBER returns TRUE when FIND yields a number, and FALSE when FIND throws the error.
Another way with COUNTIF
If all that seems a little crazy, you can also the COUNTIF function to find text:
=COUNTIF(A1,"*apple*")
It might seem strange to use COUNTIF like this, since we’re just counting one cell. But COUNTIF does the job well – if «apple» is found, it returns 1, if not, it returns zero.
For many situations (e.g. conditional formatting) a 1 or 0 result will be just fine. But if you want to force a TRUE/FALSE result, just wrap with IF:
=IF(COUNTIF(A1,"*apple*"),TRUE)
Now we get TRUE if «apple» is found, FALSE if not:
Note that COUNTIF supports wildcards – in fact, you must use wildcards to get the «contains» behavior, by adding an asterisk to either side of the text you’re looking for. On the downside, COUNTIF isn’t case-sensitive, so you’ll need to use FIND if case is important.
Other examples
So what can you do with these kind of formulas? A lot!
Here are a few examples (with full explanations) to inspire you:
- Count cells that contain specific text
- Sum cells that contain specific text
- Test a cell to see if contains one of many things
- Highlight cells that contain specific text
- Build a search box to highlight data (video)
Logical confusion?
If you need to brush up on how logical formulas work, see this video. It’s kind of boring, but it runs through a lot of examples.
Other formulas
If you like formulas (who doesn’t?!), we maintain a big list of examples.
Return to Excel Formulas List
Download Example Workbook
Download the example workbook
This tutorial demonstrates how to check if a cell contains a specific number using the FIND and ISNUMBER Functions in Excel and Google Sheets.
Check if Cell Contains Specific Number Using ISNUMBER and FIND
A cell that contains a mix of letters, numbers, spaces, and/or symbols is stored as a text cell in Excel. We can check if one of those cells contains a specific number with the ISNUMBER and FIND Functions.
=ISNUMBER(FIND(9,B3))
Let’s step through this two-part formula.
The FIND Function
First, the FIND Function checks for a specified character within a text string. It then returns the position of that character in the string, or a #VALUE! error if it is not found.
=FIND(9,B3)
In this example, the FIND Function returns the position of “9” in each cell. As shown above, for cells without the number 9, it returns a VALUE error.
Note: You can use either the FIND or SEARCH Function to check if a cell contains a specific number. Both functions have the same syntax and, with numeric find texts, produce the same result.
The ISNUMBER Function
Next, the ISNUMBER Function does what its name implies: it checks if a cell is a number and returns TRUE or FALSE.
=ISNUMBER(C3)
The ISNUMBER Function checks the result of the FIND Function and returns TRUE for cells with position numbers and FALSE for the cell with a VALUE error.
Combining these functions together gives us our original formula:
=ISNUMBER(FIND(9,B3))
Check if Cell Contains Specific Number in Google Sheets
These functions work the same in Google Sheets as in Excel.
IF function is undoubtedly one of the most important functions in excel. In general, IF statements give the desired intelligence to a program so that it can make decisions based on given criteria and, most importantly, decide the program flow.
In Microsoft Excel terminology, IF statements are also called «Excel IF-Then statements». IF function evaluates a boolean/logical expression and returns one value if the expression evaluates to ‘TRUE’ and another value if the expression evaluates to ‘FALSE’.
Definition of Excel IF Function
According to Microsoft Excel, IF function is defined as a formula which «checks whether a condition is met, returns one value if true and another value if false».
Syntax
Syntax of IF function in Excel is as follows:
=IF(logic_test, [value_if_true], [value_if_false])
'logic_test'
(required argument) – Refers to the boolean expression or logical expression that needs to be evaluated.'value_if_true'
(optional argument) – Refers to the value that will be returned by the IF function if the 'logic_test'
evaluates to TRUE.'value_if_false'
(optional argument) – Refers to the value that will be returned by the IF function if the 'logic_test'
evaluates to FALSE.
Important Characteristics of IF Function in Excel
- To use the IF function, you need to provide the
'logic_test'
or conditional statement mandatorily. - The arguments
'value_if_true'
and'value_if_false'
are optional, but you need to provide at least one of them. - The result of the IF statement can only be any one of the two given values (either it will be
'value_if_true'
or'value_if_false'
). Both values cannot be returned at the same time. - IF function throws a ‘#Name?’ error if the
'logic_test'
or boolean expression you are trying to evaluate is invalid. - Nesting of IF statements is possible, but Excel only allows this to 64 levels. Nesting of IF statement means using one if statement within another.
Comparison Operators That Can Be Used With IF Statements
Following comparison operators can be used within the 'logic_test'
argument of the IF function:
- = (equal to)
- <> (not equal to)
- < (less than)
- > (greater than)
- >= (greater than or equal to)
- <= (less than or equal to)
- Apart from these, you can also use any other function that returns a boolean result (either ‘true’ or ‘false’). For example – ISBLANK, ISERROR, ISEVEN, ISODD, etc
Now, let’s see some simple examples to use these comparison operators within the IF Function:
Simple Examples of Excel IF Statement
Now, let’s try to see a simple example of the Excel IF function:
Example 1: Using ‘equal to’ comparison operator within the IF function
In this example, we have a list of colors, and we aim to find the ‘Blue’ color. If we are able to find the ‘Blue’ color, then in the adjacent cell, we need to assign a ‘Yes’; otherwise, assign a ‘No’.
So, the formula would be:
=IF(A2="Blue", "No", "Yes")
This suggests that if the value present in cell A2 is ‘Blue’, then return a ‘Yes’; otherwise, return a ‘No’.
If we drag this formula down to all the rows, we will find that it returns ‘Yes’ for the cells with the value ‘Blue’ for all others; it would result in ‘No’.
Example 2: Using ‘not equal to’ comparison operator within the IF function.
Let’s take example 1, and understand how we can reverse the logic and use a ‘not equal to’ operator to construct the formula so that it still results in ‘Yes’ for ‘Blue’ color and ‘No’ for any other text.
So the formula would be:
=IF(A2<>"Blue", "No", "Yes")
This suggests that if the value at A2 is not equal to ‘Blue’, then return a ‘No’; otherwise, return a ‘Yes’.
When dragged down to all the below rows, this formula would find all the cells (from A2 to A8) where the value is not ‘Blue’ and marks a ‘No’ against them. Otherwise, it marks a ‘Yes’ in the adjacent cells.
Example 3: Using ‘less than’ operator within the IF function.
In this example, we have scores of some students, along with their names. We want to assign either «Pass» or «Fail» against each student in the result column.
Based on our criteria, the passing score is 50 or more.
For this, we can use the IF function as:
=IF(B2<50,"Fail","Pass")
This suggests that if the value at B2, i.e., 37, is less than 50, then return «Fail»; otherwise, return «Pass».
As 37 is less than 50 so the result will be «Fail».
We can drag the above-given formula for the rest of the cells below and the result would be correct.
Example 4: Using ‘greater than or equal to’ operator within the IF statement.
Let’s take example 3 and see how we can reverse the logic and use a ‘greater than or equal to’ operator to construct the formula so that it still results in ‘Pass’ for scores of 50 or more and ‘Fail’ for all the other scores.
For this, we can use the Excel IF function as:
=IF(B2>=50,"Pass","Fail")
This suggests that if the value at B2, i.e., 37 is greater than or equal to 50, then return «Pass»; otherwise, return «Fail».
As 37 not greater than or equal to 50 so the result will be «Fail».
When dragged down for the rest of the cells below, this formula would assign the correct result in the adjacent rows.
Example 5: Using ‘greater than’ operator within the IF statement.
In this example, we have a small online store that gives a discount to its customers based on the amount they spend. If a customer spends $50 or more, he is applicable for a 5% discount; otherwise, no discounts are offered.
To find whether a discount is offered or not, we can use the following excel formula:
=IF(B2>50,"5% Discount","No Discount")
This translates to – If the value at B2 cell is greater than 50, assign a text «5% Discount» otherwise, assign a text «No Discount» against the customer.
In the first case, as 23 is not greater than 50, the output will be «No Discount».
We can drag the above-given formula for the rest of the cells below are the result would be correct.
Example 6: Using ‘less than or equal to’ operator within the IF statement.
Let’s take example 5 and see how we can reverse the logic and use a ‘less than or equal to’ operator to construct the formula so that it still results in a ‘5% Discount’ for all customers whose total spend exceeds $50 and ‘No Discount’ for all the other customers.
For this, we can use the IF-then statement as:
=IF(B2<=50,"No Discount","5% Discount")
This means that if the value at B2, i.e., 23, is less than or equal to 50, then return «No Discount»; otherwise, return «5% Discount».
As 23 is less than or equal to 50 so the result will be «No Discount».
When dragged down for the rest of the cells below, this formula would assign the correct result in the adjacent rows.
Example 7: Using an Excel Logical Function within the IF formula in Excel.
In this example, let’s suppose we have a list of numbers, and we have to mark Even and Odd numbers. We can do this using the IF condition and the ISEVEN or ISODD inbuilt functions provided by Microsoft Excel.
ISEVEN function returns ‘true’ if the number passed to it is even; otherwise, it returns a ‘false’. Similarly, ISODD function return ‘true’ if the number passed to it is odd; otherwise, it returns a ‘false’.
For this, we can use the IF-then statement as:
=IF(ISEVEN(A2),"Even","Odd")
This means that – If the value at A2 cell is an even number, then the result would be «Even»; otherwise, the result would be «Odd».
Alternatively, the above logic can also be written using the ISODD function along with the IF statement as:
=IF(ISODD(A2),"Odd","Even")
This means that – If the value at A2 cell is an odd number, then the result would be «Odd»; otherwise, the result would be «Even».
Example 8: Using the Excel IF function to return another formula a result.
In this example, we have Employee Data from a company. The company comes up with a simple way to reward its loyal employees. They decide to give the employees an annual bonus based on the years spent by the employee within the organization.
Employees with experience of more than 5 years are given 10% of annual salary as a bonus whereas everyone else gets a 5% of annual salary as a bonus.
For this, the excel formula would be:
=IF(B2>5,C2*10%,C2*5%)
This means that – if the value at B2 (experience column) is greater than 5, then return a result by calculating 10% of C2 (annual salary column). However, if the logic test is evaluated to false, then return the result by calculating 5% of C2 (annual salary column)
Use Of AND & OR Functions or Logical Operators with Excel IF Statement
Excel IF Statement can also be used along with the other functions like AND, OR, NOT for analyzing complex logic. These functions (AND, OR & NOT) are called logical operators as they are used for connecting two or more logical expressions.
AND Function– AND function returns true when all the conditions inside the AND function evaluate to true. The syntax of AND Function in Excel is:
=AND(Logic1, Logic2, logic_n)
OR Function– OR function returns true when any one of the conditions inside the OR function evaluates to true. The syntax of OR Function in Excel is:
=OR(Logic1, Logic2, logic_n)
Example 9: Using the IF function along with AND Function.
In this example, we have Math and science test scores of some students, and we want to assign a ‘Pass’ or ‘Fail’ value against the students based on their scores.
Passing criteria: Students have to get more than 50 marks in Math and more than 70 marks in science to pass the test.
Based on the above conditions, the formula would be:
=IF(AND(B2>50,C2>70),"Pass","Fail")
The formula translates to – if the value at B2 (Math score) is greater than 50 and the value at C2 (Science Score) is greater than 70, then assign the value «Pass»; otherwise, assign the value «Fail».
Example 10: Using the IF function along with OR Function.
In this example, we have two test scores of some students, and we want to assign a ‘Pass’ or ‘Fail’ value against the students based on their scores.
Passing criteria: Students have to clear either one of the two tests with more than 50 marks.
Based on the above conditions, the formula would be:
=IF(OR(B2>50,C2>50),"Pass","Fail")
The formula translates to – if either the value at B2 (Test 1 score) is greater than 50, OR the value at C2 (Test 2 Score) is greater than 50, then assign the value «Pass»; otherwise, assign the value «Fail».
Recommended Reading: Excel NOT Function
Nested IF Statements
When used alone, IF formula can only result in two outcomes, i.e., True or False. But there are many cases when we want to test multiple outcomes with IF statement.
In such cases, nesting two or more IF Then statements one inside another can be convenient in writing formulas.
Syntax:
The syntax of the Nested IF Then statements is as follows:
=IF(condition_1,value_if_true_1,IF(condition_2,value_if_true_2,value_if_false_2))
'condition_1'
– Refers to the first logical test or conditional expression that needs to be evaluated by the outer IF function.'value_if_true_1'
– Refers to the value that will be returned by the outer IF function if the 'condition_1'
evaluates to TRUE.'condition_2'
– Refers to the second logical test or conditional expression that needs to be evaluated by the inner IF function.'value_if_true_2'
– Refers to the value that will be returned by the inner IF function if the 'condition_2'
evaluates to TRUE.'value_if_false_2'
– Refers to the value that will be returned by the inner IF function if the 'condition_2'
evaluates to FALSE.
The above syntax translates to this:
IF Condition1 = true THEN value_if_true1 'If Condition1 is true
ELSE IF Condition2 = true THEN value_if_true2 'Elseif Clause Condition2 is true
ELSE value_if_false2 'If both conditions are false
END IF 'End of IF Statement
As we can see, Nested formulas can quickly become complicated so, let’s try to understand how nesting of the IF statement works with an example.
Recommended Reading: VBA Select Case Statement
Example 11: Nested IF Statements
In this example, we have a list of countries and their average temperatures in degree Celsius for the month of January. Our goal is to categorize the country based on the temperature range as follows:
Criteria: Temperatures below 20 °C should be marked as «Below Room Temperature», temperatures between 20°C to 25°C should be classified as «Normal Room Temperature», whereas any temperature over 25°C should be marked as «Above Room Temperature».
Based on the above conditions, the formula would be:
=IF(B2<20,"Below Room Temperature",IF(AND(B2>=20,B2<=25),"Normal Room Temperature", "Above Room Temperature"))
The formula translates to – if the value at B2 is less than 20, then the text «Below Room Temperature» is returned from the outer IF block. However, if the value at B2 is greater than or equal to 20, then the inner IF block is evaluated.
Inside the inner IF block, the value at B2 is checked. If the value at B2 is greater than or equal to 20 and less than or equal to 25. Then the inner IF block returns the text «Normal Room Temperature».
However, if the condition inside the inner IF block also evaluates to ‘false’ that means the value at B2 is greater than 25, so the result will be «Above Room Temperature».
Recommended Reading: SWITCH Function in Excel
Partial Matching or Wildcards with IF Function
Although IF function itself doesn’t accept any wildcard characters like (* or ?) while performing the logic test, thankfully, there are ways to perform partial matching and wildcard searches with the IF function.
To perform partial matching inside the IF function, we can use the FIND (case sensitive) or SEARCH (case insensitive) functions.
Let’s have a look at this with some examples.
Example 12: Using FIND and SEARCH functions inside the IF statement
In this example, we have a list of customers, and we need to find all the customers whose last name is «Flynn». If the customer name contains the text «Flynn», then we need to assign a text «Found» against their names. Otherwise, we need to assign a text «Not Found».
For this, we can make use of the FIND function within the IF function as:
=IF(ISNUMBER(FIND("Flynn",A2)),"Found","Not Found")
Using the FIND function, we perform a case-sensitive search of the text «Flynn» within the customer name column. If the FIND function is able to find the text «Flynn», it returns a number signifying the position where it found the text.
If the number returned by the FIND function is valid, the ISNUMBER Function returns a value true. Else, it returns false. Based on the ISNUMBER function’s output, the logic test is performed and the appropriate value «Found» or «Not Found» is assigned.
Note: It should be noted that the FIND function performs a case-sensitive search.
This means in the above example if the customer name is entered in lower case (like «sean flynn» then the above function would return not found against them.
To perform a case-insensitive search, we can replace the find function with the search function, and the rest of the formula would be the same.
=IF(ISNUMBER(SEARCH("Flynn",A2)),"Found","Not Found")
Example 13: Using SEARCH function inside the Excel IF formula with wildcard operators
In this example, we have the same customer list from example 12, and we need to find all the customers whose name contains «M». If the customer name contains the alphabet «M», we need to assign a text «M Found» against their names. Otherwise, we need to assign a text «M Not Found».
For this, we can use the SEARCH function with a wildcard ‘*’ operator inside the IF function as:
=IF(ISNUMBER(SEARCH("M*",A2)),"M Found","M Not Found")
For more details on Search Function and wildcard, operators check out this article – Search Function In Excel
Some Practical Examples of using the IF function
Now, let’s have a look at some more practical examples of the Excel IF Function.
Example 14: Using Excel IF function with dates.
In this example, we have a task list along with the task due dates. Our goal is to show results based on the task due date.
If the task due date was in the past, we need to show «Was due {1,2,3..} day(s) back», if the task due date is today’s date, we need to show «Today» and similarly, if the task due date is in the future then we need to show «Due in {1,2,3..} day(s)»
In Microsoft Excel, we can do this with the help of the IF-then statement and TODAY function, as shown below:
=IF(B2=TODAY(),"Today", IF(B2>TODAY(),CONCAT("Due in ",B2-TODAY()," day(s)"), CONCAT("Was due ",TODAY()-B2," day(s) back")))
This means that – compare the date present in cell B2 if the date is equal to today’s date show the text «Today». If the date in cell B2 is not equal to today’s date, then the inner IF block checks if the date in B2 is greater than today’s date. If the date in cell B2 is greater than today’s date, that means the date is in the future, so show the text «Due in {1,2,3…} days».
However, if the date in cell B2 is not greater than today’s date, that means the date was in the past; in such a case, show the text «Was due {1,2,3..} day(s) back».
You can also go a step further and apply conditional formatting on the range and highlight all the cells with the text «Today!». This will help you to clearly see
Example 15: Use an IF function-based formula to find blank cells in excel.
In this example, we will use the IF function to find the blank cells in Microsoft Excel. We have a list of customers, and in between the list, some of the cells are blank. We aim to find the blank cells and add the text «blank call found!» against them.
We can do this with the help of the IF function along with the ISBLANK function. The ISBLANK function returns a true if the cell reference passed to it is blank. Otherwise, the ISBLANK function returns false.
Let’s see the formula –
=IF(ISBLANK(A2), "Blank cell found!"," ")
This means that – If the cell at A2 is blank, then the resultant text should be «Blank cell found!», however, if the cell at A2 is not blank, then don’t show any text.
Example 16: Use the Excel IF statement to show symbolic results (instead of textual results).
In this example, we have a list of sales employees of a company along with the number of products sold by the employees in the current month. We want to show an upward arrow symbol (↑) if the employee has done more than 50 sales and a downward arrow symbol (↓) if the employee has made less than 50 sales.
To do this, we can use the formula:
=IF(B2>50,$G$6,$G$8)
This implies – If the value at B2 is greater than 50, then, as a result, show the content in cell G6 (cell containing upward arrow) and otherwise show the content at G8 (cell containing downward arrow)
If you wonder about the ‘$’ signs used in the formula, you can check out this post – Excel Absolute References. These ‘$’ symbols are used for making excel cell references absolute.
Recommended Reading: CHOOSE Function in Excel
IFS Function In Excel:
IFS Function in Microsoft Excel is a great alternative to nested IF Statements. It is very similar to a switch statement. The IFS function evaluates multiple conditions passed to it and returns the value corresponding to the first condition that evaluates to true.
IFS function is a lot simple to write and read than nested IF statements. IFS function is available in Office 2019 and higher versions.
Syntax for IFS function:
=IFS (test1, value1, [test2, value2], ...)
'test1'
(required argument) – Refers to the first logical test that needs to be evaluated.
'value1'
(required argument) – Refers to the result to be returned when 'test1'
evaluates to TRUE.
'test2'
(optional argument) – Refers to the second logical test that needs to be evaluated
'value2'
(optional argument) – Refers to the result to be returned when 'test2'
evaluates to TRUE.
Example 17: Using IFS function in Excel
In this example, we have a list of students, along with their scores, and we need to assign a grade to the students based on the scores.
The grading criteria is as follows – Grade A for a score of 90 or more, Grade B for a score between 80 to 89.99, Grade C for a score between 70 to 79.99, Grade D for a score between 60 to 69.99, Grade E for a score between 60 to 59.99, Grade F for a score lower than 50.
Let’s see how easily write such a complicated formula with the IFS function:
=IFS(B2 >= 90,"A",B2 >= 80,"B",B2 >= 70,"C",B2 >= 60,"D",B2 >= 50,"E",B2 < 50,"F")
This implies that – If B2 is greater than or equal to 90, return A. Else if B2 is greater than or equal to 80, return B. Else if B2 is greater than or equal to 70, return C. Else if B2 is greater than or equal to 60, return D. Else if B2 is greater than or equal to 50, return E. Else if B2 is less than 50, return F.
If you would try to write the same formula using nested IF statements, see how long and complicated it becomes:
=IF(B2 >= 90,"A",IF(B2 >= 80, "B",IF(B2 >= 70, "C",IF(B2 >= 60, "D",IF(B2 >= 50, "E",IF(B2 < 50, "F"))))))
So, this was all about the IF function in excel. If you want to learn more about IF function, I would recommend you to go through this article – VBA IF Statement With Examples