Thread: Find String
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Find String

Hi Abdul,

Try setting the Find method's LookAt parameter to XlWhole.

For example (lightly adapting the Help example code):

'=============
Public Sub Tester001()
Dim rng As Range
Dim firstAddress As String
Const searchStr As String = "Tra*"

With ActiveSheet.Cells
Set rng = .Find(searchStr, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
firstAddress = rng.Address
Do
rng.Interior.ColorIndex = 6
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing _
And rng.Address < firstAddress
End If
End With

End Sub
'<<=============

If I ran the above code on a sheet which contained multiple examples of all
of your suggested words, only those words that commenced with the letters
'tra' were highlighted.

---
Regards,
Norman



"Abdul" wrote in message
oups.com...
Sorry, I think I did'nt make it clear..

I want to search part of a cell starting from the first character
only.. So that TRA* will find TRAvel, TRAnsport, TRAde etc but it
should exclude cenTRAl or conTRAct since it does not start with TRA

Thanks