View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default How to find a particular word?

Here is a slight modification to my macro so that the FindWord surrounded by
numbers is not considered a stand-alone word...

Sub FindExactWord()
Dim c As Range, FindWord As String, Answer As Long
Const SearchColumn As String = "B"
Const WorksheetName As String = "Sheet1"
FindWord = InputBox("What word do you want to find?")
With Worksheets(WorksheetName)
Set c = .Columns(SearchColumn).Find(FindWord, LookIn:=xlValues, _
LookAt:=xlPart, After:=Cells(.Rows.Count, "B"), _
MatchCase:=False, SearchDirection:=xlNext)
If Not c Is Nothing Then
Do
If " " & UCase(c.Value) & " " Like "*[!A-Z]" & _
UCase(FindWord) & "[!A-Z0-9]*" Then
c.Select
Answer = MsgBox("Continue searching?", vbQuestion Or vbYesNo)
If Answer = vbNo Then Exit Do
End If
Set c = .Columns(SearchColumn).FindNext(c)
Loop
Else
MsgBox "I could not find """ & FindWord & """."
End If
End With
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
The following macro will do what you want; just change the assignments in
the two Const (constant) statements at the beginning of the code to the
worksheet name and column letter that want to search in. If you want, you
can attach the macro to a button (either on the worksheet or the toolbar)
to make accessing it easier. The macro will ask you for the word or phrase
you want to find (letter casing is not important) and then locate it if it
exists in the list (or tell you that the word or phrase could not be
found)... after finding the first occurrence of the word or phrase, you
will be given the opportunity to look for its next occurrence in case the
first occurrence was not the one you wanted. This continued searching will
not end until you click the No button on the dialog box that asks you
about continuing the search.

Sub FindExactWord()
Dim C As Range, FindWord As String, Answer As Long
Const SearchColumn As String = "B"
Const WorksheetName As String = "Sheet1"
FindWord = InputBox("What word do you want to find?")
With Worksheets(WorksheetName)
Set C = .Columns(SearchColumn).Find(FindWord, LookIn:=xlValues, _
LookAt:=xlPart, After:=Cells(.Rows.Count, "B"), _
MatchCase:=False, SearchDirection:=xlNext)
If Not C Is Nothing Then
Do
If " " & UCase(C.Value) & " " Like "*[!A-Z]" & _
UCase(FindWord) & "[!A-Z]*" Then
C.Select
Answer = MsgBox("Continue searching?", vbQuestion Or vbYesNo)
If Answer = vbNo Then Exit Do
End If
Set C = .Columns(SearchColumn).FindNext(C)
Loop
Else
MsgBox "I could not find """ & FindWord & """."
End If
End With
End Sub

--
Rick (MVP - Excel)


"Jack" wrote in message
...
Hello, everybody!

I have a dictionary that I created in excel and that is becoming too
large
to find particular words. I have one problem with finding. I want to
find,
for example, 'vision,' but it finds all words containing 'vision,' i.e.
division, divisional, visionary, provision, etc. What I need is that I
want
to find only the word 'vision' in order not to waste time, finding
unrelated
words, as mentioned above.

Is there any solution to it? Please help me.

Thanks in advance.
Jack