View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
StraightEight StraightEight is offline
external usenet poster
 
Posts: 2
Default Why does a find wrongly return true when I search a variable?

My apologies for the delayed response, this was indeed (after a bit of
tweaking, headaches and frustration!) the correct method for the task
I was needing to do. Many thanks for pointing me where I should have
looked first!

Regards,
Str8

On 4 Feb, 13:37, "Jim Cone" wrote:
Review the example code in Help for the Find method.
Note the use of the Set statement and the FindNext method...
'--
With Worksheets(1).Range("a1:a500")
* * Set c = .Find(2, lookin:=xlValues)
* * If Not c Is Nothing Then
* * * * firstAddress = c.Address
* * * * Do
* * * * * * c.Interior.Pattern = xlPatternGray50
* * * * * * Set c = .FindNext(c)
* * * * Loop While Not c Is Nothing And c.Address < firstAddress
* * End If
End With
'--

Also, avoid the use of On Error Resume Next.
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins - "Find and List" - find multiple items on multiple sheets)