Check if a cell contains text (case-sensitive)

Let's say you want to find text that begins with a standard company prefix, such as ID_ or EMP-, and this text must be in uppercase letters. There are several ways to check if a cell contains text and the case of the text matters to you.

What do you want to do?


Compare one cell to another cell

To do this task, use the EXACT function.

Example

The example may be easier to understand if you copy it to a blank worksheet.

ShowHow to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note   Do not select the row or column headers.

Selecting an example from Help

Selecting an example from Help
  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
 
1
2
3
4
A
Data
BD122
BD123
BD123
Formula Description (Result)
=EXACT(A2,A3) Compare contents of A2 and A3 (FALSE)
=EXACT(A3,A4) Compare contents of A3 and A4 (TRUE)

 Note   EXACT is case-sensitive but ignores formatting differences.

Function details

EXACT

Top of Page Top of Page

Compare one value to a list of values

To do this task, use the EXACT and OR functions.

Example

The example may be easier to understand if you copy it to a blank worksheet.

ShowHow to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note   Do not select the row or column headers.

Selecting an example from Help

Selecting an example from Help
  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
 
1
2
3
4
A B
List Cell
Apple Grape
Orange
Banana
Formula Description (Result)
=OR(EXACT(B2, A2:A4)) Compares "Grape" to each value in the list (FALSE)

 Note   The formula in the example must be entered as an array formula (array formula: A formula that performs multiple calculations on one or more sets of values, and then returns either a single result or multiple results. Array formulas are enclosed between braces { } and are entered by pressing CTRL+SHIFT+ENTER.). After copying the example to a blank worksheet, select each formula cell individually. Press F2, and then press CTRL+SHIFT+ENTER. If the formula is not entered as an array formula, the error #VALUE! is returned.

Function details

OR

EXACT

Top of Page Top of Page

Check if part of a cell matches specific text

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

 Note   The FIND function is case-sensitive.

Example

The example may be easier to understand if you copy it to a blank worksheet.

ShowHow to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note   Do not select the row or column headers.

Selecting an example from Help

Selecting an example from Help
  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
 
1
2
3
A
Data
Davolio
BD123
Formula Description (Result)
=IF(ISNUMBER(FIND("v",A2)),"OK", "Not OK") Checks to see if A2 contain the letter v (OK)
=ISNUMBER(FIND("BD",A3)) Checks to see if A3 contains BD (TRUE)

The formula above uses the following arguments.


Formula to check for text

Formula to check for text

Callout 1 search_for: What you want to check for.
Callout 2 to_search: The cell that contains the text that you want to check.

Function details

IF

ISNUMBER

FIND, FINDB

Top of Page Top of Page

 
 
Applies to:
Excel 2007