How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (2024)

We have a table that contains student information and their grades. We will check if a cell contains specific text.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (1)

Method 1 – Using the IF Function to Check If a Cell Contains an Exact Text in Excel

The Grade column has Passed or Failed in every cell. We will check whether a cell contains Passed and add a remark in a seocndRemarks column.

  • Use the following formula in E5 to check whether the cell D5 contains the specific text Passed.

=IF(D5="Passed","Promoted","")

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (2)

Formula Breakdown

  • We have set a logical operation D5=Passed” that compares if the D5 contains “Passed” or not.
  • For if_true_value ,we have set Promoted, which will appear as a result once it finds the cell contains the text.
  • No if_false_value is provided.
  • Hit Enter to get the first result.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (3)

  • Repeat the formula for the rest of the cells. Alternatively, you can drag or double-click the Fill Handle icon to paste the used formula to the other cells of the column.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (4)

Our formula has returned the if_true_valuePromoted for the cells that contain Passed. This check is not case-insesitive, so the formula will register text strings that don’t use lowercase letters.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (5)

Method 2 – Combining the IF and EXACT Functions to Check If a Cell Contains Specific Text

We will check whether a cell contains the exact text Passed and add a remark in the Remarks column.

  • Use the formula given below in the E5 cell.

=IF(EXACT("Passed",D5),"Promoted","")

  • Press Enter.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (6)

Formula Breakdown

  • We have set a logical operation EXACT(“Passed”,D5) that compares the text in the D5 cell with Passed.
  • For the if_true_value, we have set Promoted, which will appear as a result if the formula finds a cell containing the text.
  • No if_false_value is provided.
  • Drag the Fill Handle icon down to AutoFill the corresponding data in the rest of the cells E6:E14.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (7)

Method 3 – Joining IF, ISNUMBER, FIND, and MID Functions to Search for a Specific Text (Case-Sensitive)

We will search for a string (group name) within the cells of the ID column.

Here, we have introduced a couple of columns that match the context of our example. We chose the string “XG” that we will search within cells from the ID column. The lookup value is in E5 (a merged cell).

  • Use the following formula in the F5 cell.

=IF(ISNUMBER(FIND($E$5,B5)),MID(B5,FIND($E$5,B5),2),"")

  • Press Enter.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (8)

Formula Breakdown

  • ISNUMBER returns TRUE when a cell contains a number, and FALSE if not.
  • We used this function because it checks whether the FIND function’s result is a number or not. It returns a boolean value.
  • When the ISNUMBER returns TRUE, the IF function will trigger the if_true_value. Otherwise, it goes to if_false_value.
  • In the case of if_true_value term, we will extract the group name.
  • For extracting the group name, we will use the MID function. This function extracts characters from the middle of a given string. FIND within MID provides the starting point and then MID extracts 2 characters from that point. This is due to the lookup string being two characters long.
  • Drag the Fill Handle icon to AutoFill the corresponding data in the rest of the cells F6:F14.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (9)

Method 4 – Combining IF, ISNUMBER, SEARCH, and MID Functions to Find a Specific Text (Case-Insensitive)

  • Use the following formula in the F5 cell.

=IF(ISNUMBER(SEARCH($E$5,B5)),MID(B5,SEARCH($E$5,B5),2),"")

  • Press Enter.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (10)

Formula Breakdown

  • ISNUMBER returns TRUE when a cell contains a number, and FALSE if not.
  • We used this function because it checks whether the SEARCH function’s result is a number or not. It returns a boolean value.
  • When the ISNUMBER returns TRUE then the IF function will trigger the if_true_value. Otherwise the if_false_value.
  • In the case of if_true_value term we will extract the group name.
  • For extracting the group name, we will use the MID function. This function extracts characters from the middle of a given string. Basically, SEARCH within MID provides the starting point and then 2 characters. This will fetch the two-character group names.
  • Double-click on the Fill Handle icon to AutoFill the corresponding data in the rest of the cells F6:F14.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (11)

Method 5 – Merging IF, COUNTIF, SEARCH, and MID Functions to Find a Particular Text (Case-Insensitive)

  • Use the following formula in F5.

=IF(COUNTIF(B5,"*"&$E$5&"*"),MID(B5,SEARCH($E$5,B5),2),"")

  • Hit Enter.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (12)

Formula Breakdown

  • W have checked the logic using COUNTIF. Using COUNTIF it checks whether the count value is 1 or not.
  • If COUNTIF returns 1, the if_true_value (MID portion to extract group name) will be returned. Furthermore, the MID portion is discussed in the earlier section.
  • For 0 from the COUNTIF portion, the formula will return if_false_value (empty cell, for the time being).
  • AutoFill the formula through the column.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (13)

For more COUNTIF partial match approaches, visit this COUNTIF Partial Match article.

Method 6 – Joining ISNUMBER and SEARCH Functions to Check If a Cell Contains Specific Text in Excel (Case-Insensitive)

  • Use the formula given below in the F5 cell.

=ISNUMBER(SEARCH(E5,B5:B14))

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (14)

  • Hit Enter and AutoFill.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (15)

Method 7 – Joining SUMPRODUCT and COUNTIF Functions to Search for a Specific Text (Case-Insensitive)

  • Use the following formula in F5.

=SUMPRODUCT(COUNTIF(B5,"*"&$E$5&"*"))>0

  • Hit Enter.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (16)

Formula Breakdown

  • The range is B5:B10.
  • Criterion is “*”&D5&”*”.
  • The COUNTIF function counts the number of matched cells.
  • The SUMPRODUCT function takes the number returned by the COUNTIF function and gets its sum.
  • Apply the same formula to the rest of the cells via AutoFill.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (17)

Method 8 – Applying Excel VBA to Check If a Cell Contains Specific Text

Steps:

  • Go to the Developer tab and select Visual Basic.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (18)

  • From the Insert tab, select Module.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (19)

  • Insert the following Code in the Module.
Sub If_Contains_Specified_Text()If InStr(ActiveCell.Value, "Passed") > 0 ThenMsgBox "This cell contains that specified text."ElseMsgBox "This cell doesn't contain that text."End IfEnd Sub

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (20)

Code Breakdown

  • Here, we have created a Sub Procedure named If_Contains_Specified_Text.
  • InStr will search for the string Passed.
  • We used a MsgBox to show the result.
  • Save the code by pressing Ctrl + S. Use the type extension .xlsm.
  • Go back to the Excel worksheet.
  • Select any cell from the Grade column.
  • From the Developer tab, select Macros.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (21)

  • Select the Macro (If_Contains_Specified_Text) and click on Run.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (22)

  • You will find a message that displays the result.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (23)

  • We have selected another cell D7 and got the following message.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (24)

Practice Section

Use the practice dataset in the download file to test these methods yourself.

How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (25)

Download the Practice Workbook

If Cell Contains Specific Text.xlsm

<< Go Back to Find in String | String Manipulation | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
How to Check If Cell Contains Specific Text in Excel (8 Methods) - ExcelDemy (2024)
Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 5508

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.