Find exact text match
Always best to include the Find function's optional arguments, which can be
left in an unknown state by previous manual use of Find.
change
Set C = .Find(Cells(N, 14).Value, LookIn:=xlValues)
to
Set c = .Find(Cells(N, 2).Value, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
I want it to find an exact match
use LookAt:=xlWhole
If you want case sensitive change MatchCase:=False to MatchCase:=True
The example is suitable for use in XL 97 & 2000, it's probably OK to omit
other arguments introduced in later versions.
Regards,
Peter T
"Graham" wrote in message
...
I am having a problem with the part of a procedure below in that I want it
to find an
exact match and it does not do that. For example Cells(n,14) at any point
may have SB and
the loop is picking up NF-TSB in Rng. I would value any guidance.
Set Rng = Range("AA1:AA30")
With Rng
For N = 15 To 42
Set C = .Find(Cells(N, 14).Value, LookIn:=xlValues)
If Not C Is Nothing Then
firstAddress = c.Address
Do
----STATEMENTS
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
Next
End With
Kind Regards,
Graham
|