Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Returning a Cell Address

Just want to know how to search a worksheet for a name (for instance) and
return the address of the cell.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Returning a Cell Address

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struggling with returning a cell address Oddjob Excel Discussion (Misc queries) 0 October 27th 09 09:48 PM
Returning a cell address in a msgbox, by selection via inputbox Ty FARAZ QURESHI Excel Discussion (Misc queries) 3 April 8th 09 12:57 PM
Returning an address from an array wienmichael Excel Discussion (Misc queries) 6 May 2nd 07 02:53 AM
returning the address of a value Excel Enthusiastic Excel Discussion (Misc queries) 1 April 11th 07 05:40 PM
VBA returning a cell address [email protected] Excel Programming 3 September 30th 03 04:59 PM


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"