ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find String (https://www.excelbanter.com/excel-programming/362684-find-string.html)

Abdul[_2_]

Find String
 
Hello!,


By using the find option we could search for part of a cell or whole
cell content.

But if it possible to search using wild cards starting from the
beginning of the cell?

Like match the starting charecters only...

Tra* will find TRAvel, TRAnsport, TRAde etc but not cenTRAl or conTRAct
?!!!

THANKS


Bob Phillips

Find String
 
Try it and see.

--
HTH

Bob Phillips

(replace somewhere in email address with googlemail if mailing direct)

"Abdul" wrote in message
oups.com...
Hello!,


By using the find option we could search for part of a cell or whole
cell content.

But if it possible to search using wild cards starting from the
beginning of the cell?

Like match the starting charecters only...

Tra* will find TRAvel, TRAnsport, TRAde etc but not cenTRAl or conTRAct
?!!!

THANKS




Abdul[_2_]

Find String
 
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


Norman Jones

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





All times are GMT +1. The time now is 04:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com