Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. 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: Searching for a Value Using a Function.
by Allen Wyatt
(last updated February 13, 2016)
Thor wonders if there is a way to perform a lookup without having to specify a column or row and having the result be the address of the cell at which the value is found. For instance, he wants to look up a value (such as 345 or "my text") and have the function search all the cells in all the worksheets in the workbook and return the full address of the cell in which the value was found.
The approach you use will be dictated by the range you want to search. If you want to search on the same worksheet on which you want the answer displayed, then you can use a formula, such as the following:
=ADDRESS(MAX(ROW(1:5)*(A1:E5="my text")), MAX(COLUMN(A1:E1)*(A1:E5="my text")),4)
This should be entered as an array formula (press Ctrl+Shift+Enter), and it only searches in the range A1:E5. You can, if desired, change the range by adjusting the formula appropriately.
A larger search area would be to look at an entire worksheet. This can still be done using an array formula, such as the following:
The formula assumes that what you are looking for is stored in cell A1. You should change the Sheet1 designation to the name of whatever worksheet you want searched.
If you want to search a wider range, such as all the worksheets in a workbook, then the best solution is to use a macro that calls upon the Find function within Excel.
Function FindAddr(vValue As Variant) Dim wks As Worksheet Dim rCell As Range Dim bFound As Boolean bFound = False For Each wks In ActiveWorkbook.Worksheets With wks Set rCell = .Cells.Find _ (What:=vValue, After:=.Cells(1), _ LookIn:=xlValues, LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not rCell Is Nothing Then bFound = True Exit For End If End With Next If bFound Then FindAddr = wks.Name & "!" & _ rCell.Address(False, False) Else FindAddr = "Not Found" End If Set wks = Nothing Set rCell = Nothing End Function
This function is designed to be called from another macro, which passes it whatever should be searched for in the vValue parameter. The function returns either the full address (including worksheet name) of the first match, or it returns "Not Found" if there was no match.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11524) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Searching for a Value Using a Function.
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!
If you want to add up the contents of a range of cells based on what is contained in a different range of cells, you need ...Discover More
If you need to randomly match up items in two lists, there are a variety of techniques you can use. Here are a couple of ...Discover More
When analyzing your numeric data, you may need to figure out the largest and smallest numbers in a set of values. If you ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.