hearts006
03-09-2009, 02:22 AM
Hi all,
I am writing a function to search for "monday", if it is not present, then it will search for "- monday". if both are not present, it will search for "-monday".
But the below code snippet, fails at second find, ie, tryin to find for "- monday"
--------------------------
Assume strWord = Monday
--------------------------
public function findWord()
strWord1 = strWord
find:
Range("A1").Select
Columns("A:A").Select
On Error GoTo ErrHandler1:
Cells.find(What:=strWord1, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
strTransWord = Range("B" & ActiveCell.Row).Value
ErrHandler1:
If Err.Number = 91 Then
strTransWord = ""
End If
If strTransWord = "" Then
If strWord1 = strWord Then
strWord1 = "- " & strWord
Err.Clear
GoTo find:
ElseIf strWord1 = "- " & strWord Then
strWord1 = "-" & strWord
Err.Clear
GoTo find:
End If
End If
End Function
I am writing a function to search for "monday", if it is not present, then it will search for "- monday". if both are not present, it will search for "-monday".
But the below code snippet, fails at second find, ie, tryin to find for "- monday"
--------------------------
Assume strWord = Monday
--------------------------
public function findWord()
strWord1 = strWord
find:
Range("A1").Select
Columns("A:A").Select
On Error GoTo ErrHandler1:
Cells.find(What:=strWord1, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
strTransWord = Range("B" & ActiveCell.Row).Value
ErrHandler1:
If Err.Number = 91 Then
strTransWord = ""
End If
If strTransWord = "" Then
If strWord1 = strWord Then
strWord1 = "- " & strWord
Err.Clear
GoTo find:
ElseIf strWord1 = "- " & strWord Then
strWord1 = "-" & strWord
Err.Clear
GoTo find:
End If
End If
End Function