Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Where Is that Text?.

Where Is that Text?

Written by Allen Wyatt (last updated February 1, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365

Jay needs to determine the cell in which a particular text value occurs. He knows he can use Excel's Find and Replace capabilities to manually determine the address of cells containing a text value, but he is looking for a formula to determine the address of the cells. He wonders if there is a way to search for piece of text within a range and have Excel return the address of the cell in which the text is found.

There are two things you can try. First, if you are looking for an exact match for cell contents, then you can use a formula. The basic formula is this:

```=ADDRESS(MATCH(C2,A:A,0),1)
```

In this example, cell C2 contains the value you are looking for and column A is the range of cells being searched. The formula returns a result regardless of the capitalization of C2 or the values in column A. Thus, if C2 contains "apple", then the formula will match positively to cells that contain "apple," "Apple," or "APPLE." Indeed, any mix of capitalization will match.

This formula will not return an address for a cell that contains what you are searching for amidst other text. So if you are searching for "apple" (cell C2), it won't return the address of a cell that contains the phrase "apple crisp." You can modify this behavior, a bit, by adding wild card characters to the search cell. For instance, if you search for "*apple*" then the formula returns the address of a cell that contains "apple", even if it is preceded or followed by other characters.

It should be pointed out that this formula only returns the address of the first cell in the range which meets the criteria. If you actually want the addresses of all cells that meet the criteria, then you'll need to rely on a macro. The following is a good example:

```Function FindMe(x As Range, y As String) As String
Dim r As Range
Dim sResults As String
Dim sSearch As String

Application.Volatile
sSearch = LCase(y)
For Each r In x
If InStr(1, LCase(CStr(r.Value)), sSearch) > 0 Then
sResults = sResults & r.Address & ", "
End If
Next r
If Len(sResults) > 2 Then
FindMe = Left(sResults, Len(sResults) - 2)
Else
FindMe = ""
End If
End Function
```

You use the function by simply providing the range you want to search along with what you want to search for:

```=FindMe(A:A, "apple")
```

If you use a large range (as in this example—all of column A), then don't be surprised if the function takes a noticeable amount of time to return a result. This makes sense, as it has to search through every cell in the range, regardless of whether there is anything in the cell or not.

You also don't need to use any wildcards with this function; it assumes that a match occurs if what you are looking for is located anywhere within the cell. It also doesn't pay attention to the capitalization of what you are looking for or the capitalization of anything in the search range.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10083) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Where Is that Text?.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Tracing Precedent Cells

Cells that affect another cell are called precedent cells. If you need to know which cells affect a particular cell, ...

Discover More

Quickly Transposing Cells

If you want to turn a range of cells by 90 degrees within a worksheet, you need to understand how Excel can handle the ...

Discover More

Creating a Table of Contents from TOC Fields

If you inserted a bunch of TOC fields in your document, you can create your table of contents quite easily based on those ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Simulating Alt+Enter in a Formula

You can use the Alt+Enter keyboard shortcut while entering information in order to force your data onto multiple lines in ...

Discover More

Calculating an Average within a Date Range

Need to find an average of the values that fall within a date range? Excel provides a number of ways you can do this, ...

Discover More

Summing Only the Largest Portion of a Range

Given a range of cells, you may at some time want to calculate the sum of only the largest values in that range. Here is ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. Youâ€™ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 3?

2020-02-06 10:10:42

Gary

That is great Peter- thanks a lot!!

Gary

2020-02-05 14:55:11

Peter Atherton

Gary,
If you insert the second line above the first the function will return a zero length string (Not a Blank)

sSearch = LCase(y)
If Len(y) = 0 Then Exit Function

Peter

2020-02-05 10:20:25

Gary

Thank you Peter! That worked. I would definitely add this bit of information to the instructions above. Also, if the cell containing the text I want to find is blank, it just returns the addresses of every cell in the range. It would better if the function gave you an option for an alternate value if the cell is blank.

Gary

2020-02-04 13:58:37

Peter Atherton

Gary,
You need to include the full path to the Personal workbook. Click the Function Insert button at the left of the formula Bar and drill down to User Defined category and insert the function from there and Excel will include the full path for you.

2020-02-03 18:51:51

Gary

I tried adding this code to a module in my Personal workbook, however, when I attempt to use the function I get a #NAME? error. What might be the problem?

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)