View Full Version : Find

12-04-2006, 03:00 AM
I have a string and i need to search if a word is present in the string. I want to do this in a macro.
eg: My String "This is a String" now in the macro i need to search in the above string contains "String". If the string is present i need to do some other steps else display message not found.

12-04-2006, 03:24 AM
Dim myString As String
myString = "This is a String"
If InStr(myString, "String") > 0 Then
'do something
MsgBox "Not Found"
End If

12-04-2006, 06:56 AM
Hi Michael,
A meaningful title is more useful to the forum, eg, "Find text in a string"

Simon Lloyd
12-04-2006, 07:22 AM
The code below isnt mine it was kindly donated, but it only takes around 2.5 secs to find the word in 10000 rows and 256 columns!Sub FindWordMATCHFunct()
Dim c As Range, Rng As Range, rng2 As Range, str As String
str = InputBox("Enter string","String Finder")
Set Rng = Range("a1:iv10000")
For i = 1 To 256
Set rng2 = Range(Cells(1, i), Cells(10000, i))
If Not IsError(Application.Match(str, rng2, 0)) Then
x = Application.Match(str, rng2, 0)
MsgBox str & " Found at " & Cells(x, i).Address
Cells(x, i).Select
End If
End SubHope it helps1