Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just want to know how to search a worksheet for a name (for instance) and
return the address of the cell. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If the value to be found occurs only once (or you are interested in
only the first occurrence), use Sub AAA() Dim FoundCell As Range Dim WS As Worksheet Set WS = Worksheets("Sheet1") ' search entire sheet for "abc" Set FoundCell = WS.UsedRange.Find(what:="abc", LookIn:=xlValues, _ lookat:=xlWhole, MatchCase:=False) If FoundCell Is Nothing Then Debug.Print "not found" Else Debug.Print "Found in cell: " & FoundCell.Address End If End Sub If you want to find all the occurrences, you can use the FindAll procedure at http://www.cpearson.com/Excel/findall.aspx , which returns a Range object containing all of the cells in which the value was found. You can then loop through the results of FindAll to get all the occurrences: Dim FoundCells As Range Dim R As Range Set FoundCells = FindAll(...) If Not FoundCells Is Nothing Then For Each R In FoundCells Debug.Print FoundCell.Address,FoundCell.Value Next R End If I also have a graphical user interface for FindAll implemented as an xla add-in at http://www.cpearson.com/Excel/findallxla.aspx Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Tue, 27 Jan 2009 13:33:02 -0800, wlmjayhd wrote: Just want to know how to search a worksheet for a name (for instance) and return the address of the cell. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Struggling with returning a cell address | Excel Discussion (Misc queries) | |||
Returning a cell address in a msgbox, by selection via inputbox Ty | Excel Discussion (Misc queries) | |||
Returning an address from an array | Excel Discussion (Misc queries) | |||
returning the address of a value | Excel Discussion (Misc queries) | |||
VBA returning a cell address | Excel Programming |