View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Find next cell that contains

I have a procedure called FindAll that will find all occurrences of a
value within a range and returns a Range containing all of the found
cells. You could use that procedure to get all the matches and then
simply jump from one found cell to the next. For example,

Sub AAA()

Dim FoundCells As Range
Dim Res As VbMsgBoxResult
Dim R As Range

Set FoundCells = FindAll(SearchRange:=Range("A10:K100"), _
FindWhat:=Range("A3"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False)

If Not FoundCells Is Nothing Then
For Each R In FoundCells
Application.Goto R, True
Res = MsgBox("Item found. Continue?", vbYesNo)
If Res = vbNo Then
Exit For
End If
Next R
Else
MsgBox "Value not found.", vbOKOnly
End If

End Sub


You can download the FindAll function module from
http://www.cpearson.com/excel/FindAll.aspx . The functionality of
FindAll is also wrapped into an add-in, available 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 Thu, 19 Feb 2009 08:49:01 -0800, FirstVette52 <(My User name is
Firstvette 52, too) firstvet52@(my ISP E-mail provider is)
netzero.com wrote:

Here is my code for the initial 'FIND':
Sub SEARCH()
Dim c As Range
Dim s
s = Range("A3").Value
Set c = Cells.Find(What:=s, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
c.Select
End Sub

It works great, but it's insufficient for what I'm wanting to accomplish and
I'm not good enough with this code to get to the next level.