mikefromUK
New Member
- Joined
- Oct 15, 2002
- Messages
- 42
I am clearly missing something here. I want to test if a particular string is present in a particular worksheet. I don't wish to replace it - just test if it is there. Rather than using the Find method which returns a range, I have used the replace method which returns a boolean variable, replacing the found string with the replace string, ie nothing changes. The replace should return "true" if at least one replace occurs, false if it cannot find the strFindString. Problem: the replace action is returning true, regardless of whether or not it finds the text. It even returns true on an empty spreadsheet? Any ideas. Below is a quick program is "mocked" up to show you what I mean.
Option Explicit
Sub test()
Dim strFindString
strFindString = "australia"
Sheet1.Select
If ActiveSheet.Cells.Replace(What:=strFindString, Replacement:=strFindString, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False) = True Then
MsgBox ("condition true")
End If
End Sub
Option Explicit
Sub test()
Dim strFindString
strFindString = "australia"
Sheet1.Select
If ActiveSheet.Cells.Replace(What:=strFindString, Replacement:=strFindString, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False) = True Then
MsgBox ("condition true")
End If
End Sub