PDA

View Full Version : Find



michaelm702
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.

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

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

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
Next
End SubHope it helps1

Regards,
Simon