View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Finding rows that contain Keyword1and Keyword2 in any part of field in Column A, B or D

I think you meant that rows 2 and 4 would be retrieved, not rows 3 and 4,
right? If so, give this code a try...

Dim X As Long, Joined As String, Answer As String
Dim R As Range, SearchRange As Range, RowSlice As Range
Set SearchRange = Intersect(ActiveSheet.UsedRange, _
Union(Range("A:B"), Columns("D")))
For X = 1 To SearchRange.Rows.Count
Set RowSlice = Intersect(Rows(X), SearchRange)
Joined = ""
For Each R In RowSlice
Joined = Joined & Chr(1) & R.Value
Next
If InStr(1, Joined, "Keyword1", vbTextCompare) 0 And _
InStr(1, Joined, "Keyword2", vbTextCompare) 0 Then
Answer = Answer & X & ","
End If
Next
Answer = Left(Answer, Len(Answer) - 1)
MsgBox Answer

--
Rick (MVP - Excel)


"u473" wrote in message
...
I need to find rows that contain Keyword1and Keyword2 in any part of
field in Column A, B or D
For instance :

Col.A Col.B Col.D
1. WordX Keyword1 WordZ
2. Keyword2 WordY Prefix&Keyword1
3. Keyword1
4. Keyword1 WordZ Keyword2&Suffix

In this case, rows 3 and 4 would be retrieved
Help appreciated,
J.P.