Thread: search question
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default search question

you need to surround with a for/each. Example

sub ColorIt()
On Error Resume Next
For Each c In [colorlist]
With ActiveSheet.Cells
Set x = .Find(c, LookIn:=xlValues)
If Not x Is Nothing Then
firstAddress = x.Address
Do
x.Interior.ColorIndex = 36 '19
x.Offset(1).Interior.ColorIndex = 36 '19
Loop While Not x Is Nothing And x.Address < firstAddress
End If
End With
Next
End Sub

--
Don Guillett
SalesAid Software

"Leo" wrote in message
om...
Hi!
I search data on worksheet by simpe code from Excel help:
Sub Find_Complex()
Worksheets(2).Cells.Clear
With Worksheets(1).[a1:a500]
TextForSearch = Worksheets(1).[b1]
Set c = .Find(TextForSearch, LookIn:=xlValues)
i = 1
If Not c Is Nothing Then
firstAddress = c.Address
Do
Worksheets(2).Cells(i, 1) = c
Set c = .FindNext(c)
i = i + 1
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
End Sub
It works fine until I want find 2 values - one from [b1],
and second - for example in [b2] - code must return values from data
that contain [b1] OR [b2] ,e.g. if [b1]=1,[b2]=2 code must return all

records
from data with "1" and "2" to the same column on Worksheet(2)

How can I modify Find method for 2 values ?
Thank for help
Leo