Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Where Is that Text?.
Written by Allen Wyatt (last updated June 19, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
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:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10082) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Where Is that Text?.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Define a named range today and you may want to change the definition at some future point. It's rather easy to do, as ...
Discover MoreIf you have a list of data in a column, you may want to determine an average of whatever the last few items are in the ...
Discover MoreSometimes making sure that a reference in a formula doesn't get changed is not as simple as putting dollar signs in front ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2015-10-17 05:05:59
ENET
I am using sql to retrieve data from a excel table and the vbscript also in the same workbook. which works fine!
But I need to run that script and get result, from another workbook. is there any way to do that.
I have tried so many scripts on net on this, nothing works. As the sql does not accept full path of workbook+sheetname+rangeaddress.
thanks in advance
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments