Sub: finding a precise value

  • Thread starter Thread starter monika
  • Start date Start date
M

monika

Hi...

I am giving a search for word column name "package" through
Cells.Find("Package"). If it finds Package2 ..then also it
returns a true
value.... Is there a way to precisely find "Package"????

Thanks
monika
 
Monika,

Don't know how to do it in the find, but you could try this

Function FindIt()
Dim oFind As Range
Dim sFirst As String
Dim sFind As String

With Columns(1)
sFind = "Package"
Set oFind = .Find(sFind)
sFirst = oFind.Address
Do
If Not oFind Is Nothing Then
If Len(oFind.Value) <> Len(sFind) Then
Set oFind = .FindNext(oFind)
End If
End If
Loop While Not oFind Is Nothing And oFind.Address <> sFirst And
Len(oFind.Value) <> Len(sFind)
End With
If Not oFind Is Nothing Then MsgBox oFind.Address
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
What does precisely mean?

Does it mean Package that is the only value in a cell?

Or does it mean "whole words only" like in word--when the word can be
intermingled with a cell?

Excel supports the "match entire cell contents", but doesn't support the "whole
word" like word.
 
hi,

I wanted exactly what Bob has given the solution as ... to find out the
length of the word and compare...

thanks again ...

Monika
 
Back
Top