LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Search multiple strings in each cell

Don't do a second find. Just use instr() and look for a case sensitive match.

If you find the lower case version, then do what you want, else do another find.

Option Explicit
Sub testme()

Dim FirstWord As String
Dim SecondWord As String
Dim FirstAddress As String
Dim FoundCell As Range
Dim FoundRng As Range
Dim RngToSearch As Range
Dim myCell As Range

FirstWord = "Blackberry"
SecondWord = LCase(FirstWord) 'is this ok

With Worksheets("Input data")
Set RngToSearch = .Range("G1", .Cells(.Rows.Count, "G").End(xlUp))
End With

With RngToSearch
Set FoundCell = .Cells.Find(what:=FirstWord, _
after:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=True)

Set FoundRng = Nothing
If FoundCell Is Nothing Then
'do nothing
Else
FirstAddress = FoundCell.Address
Do
'really look at formulas? Not .value???
If InStr(1, FoundCell.Formula, SecondWord, _
vbBinaryCompare) 0 Then
If FoundRng Is Nothing Then
Set FoundRng = FoundCell
Else
Set FoundRng = Union(FoundRng, FoundCell)
End If
End If
Set FoundCell = .FindNext(after:=FoundCell)

If FoundCell.Address = FirstAddress Then
Exit Do
End If
Loop
End If

If FoundRng Is Nothing Then
MsgBox "Not found!"
Else
For Each myCell In FoundRng.Cells
MsgBox myCell.Address(0, 0)
'or do what you want to each of them
Next myCell
End If
End With

End Sub




Jeff wrote:

capitalization Find.

SearchString1 = Blackberry
SearchString2 = blackberry

Please Help. :-)

I need to Find two matches in a cell.
I need to find the first and second searchstring in a cell,
then move move down to the next cell and do it all over
again for the next cell in the column.

The problem is the second SearchString2 starts a find
all over again from the first word in the cell.

'====================================

Set rngToSearch = Sheets("Input data").Columns("G")
On Error Resume Next
Set rng = Range("G2", Cells(Rows.Count, "G").End(xlUp))
Set rngFound = rngToSearch.Find(What:=SearchString1, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=True)
On Error GoTo 0
For Each c In rng
'find first SearchString1
For Each c in rng
Set rngFound = rngToSearch.Find(What:=SearchString2, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=True)
'find second SearchString2
Next c
Next c

'=================================

you help is very much appreciated

Jeff
--
Jeff


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling Multiple Text Strings in a One Cell RebLan Excel Discussion (Misc queries) 4 April 19th 10 03:41 PM
search for multiple strings Lea from CA[_2_] Excel Discussion (Misc queries) 4 October 16th 09 10:20 PM
Search for multiple strings in a list (w/in 1 cell) w/ Advanced fi Maher Excel Discussion (Misc queries) 5 July 7th 08 06:02 PM
Search multiple strings Difficult to figure out Jeff Excel Programming 2 November 23rd 06 04:18 AM
How to make a cell recognize multiple text strings? Tourcat Excel Worksheet Functions 1 February 8th 05 08:29 PM


All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"