LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Finding rows that contain Keyword1and Keyword2 in any part of field in Column A, B or D

It was not clear to me from your initial posting what you wanted to do with
the row numbers. Here is a modification to my previously posted code to put
the row numbers in an array named RowNumbers with indexes from 1 to the
number of rows meeting your criteria.

Dim X As Long, Index As Long, RowNumbers() As Long
Dim R As Range, SearchRange As Range, RowSlice As Range, Joined As String
Set SearchRange = Intersect(ActiveSheet.UsedRange, _
Union(Range("A:B"), Columns("D")))
ReDim RowNumbers(1 To SearchRange.Rows.Count)
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
Index = Index + 1
RowNumbers(Index) = X
End If
Next
ReDim Preserve RowNumbers(1 To Index)
' Let's see the results
For X = 1 To UBound(RowNumbers)
MsgBox RowNumbers(X)
Next

The last three lines just show you the result of the code above them... at
this point in the code, you would simply process the RowsNumbers array as
needed rather then MessageBox'ing them.

--
Rick (MVP - Excel)


"u473" wrote in message
...
Thanks a lot, you were right for my test sample.
It works fine, however, how do I handle it if I have more than one
answer ?
I will try putting the answer in a loop.


 
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
Copying rows values on one sheet to part of a formula in a column Manosh Excel Discussion (Misc queries) 3 June 23rd 09 03:37 PM
finding, sorting, put only part of a cell Debilee Excel Worksheet Functions 4 October 10th 07 11:01 PM
Finding MAX Value of Part of Cell Contents Corey Excel Programming 2 January 12th 07 03:42 AM
finding part of fole path sheila Excel Worksheet Functions 3 December 4th 05 05:23 AM
Deleting rows A to E when finding dublicated Data in Column B bkbri[_3_] Excel Programming 6 December 15th 03 01:16 AM


All times are GMT +1. The time now is 08:33 AM.

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

About Us

"It's about Microsoft Excel"