Using the FIND method with AND/OR operators. Possible?

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
912
Office Version
  1. 365
Platform
  1. Windows
Problem: Find all occurrences of "green tree" AND "red fish" OR "blue ink" AND "people will help you".
These are enough examples to set the issue. The standard FIND method works great - for only ONE item word or phrase. - what if a user wants to FIND several unique words or phrases in one search? Can that be done? The following works great for ONE value or phrase only:
Code:
Private Sub cmdFIND_Click()
Sheets("RESULT").UsedRange.ClearContents
Dim lastrow As Integer
Dim x As String
Dim c As Range
Dim rw As Long
Dim firstAddress As Variant
Dim Rowno As Variant
x = Me.TextBox6.Value 'enter any word or  phrase. 
With Worksheets("Sheet2").Range("C1:C31103")
    Set c = .FIND(x, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
     rw = 1
      firstAddress = c.Address
      Do
       Worksheets("Sheet2").Select
       c.Select
       Range(Cells(c.Row, 2), Cells(c.Row, 7)).Copy Destination:=Sheets("RESULT").Range("B" & rw)
'       Range(Cells(c.Row, 2), Cells(c.Row, 7)).Copy Destination:=Sheets("RESULTA").Range("B" & rw) 'just makes an extra copy to another sheet
      rw = rw + 1
     Set c = .FindNext(c)
     Loop While Not c Is Nothing And c.Address <> firstAddress
     lastrow = Sheets("RESULT").Range("B" & Rows.count).End(xlUp).Row
     If lastrow = 1 Then
     Range(Cells(c.Row + 7, 2), Cells(c.Row, 7)).Copy Destination:=Sheets("RESULT").Range("B" & rw)
'     Range(Cells(c.Row, 2), Cells(c.Row, 7)).Copy Destination:=Sheets("RESULTA").Range("B" & rw)
    Else
    End If
 End If
 Sheets("Sheet3").Select
End With
Rowno = Sheets("RESULT").Range("B2").End(xlDown).Row
'RownoA = Sheets("RESULTA").Range("B2").End(xlDown).Row
Sheets("RESULT").Range("H1").Value = Rowno
Sheets("RESULT").Range("I1").Value = x
'Sheets("RESULTA").Range("H1").Value = Rowno
'Sheets("RESULTA").Range("I1").Value = x
ListBox1.ListIndex = 0
Me.TextBox17.Value = lastrow
Me.TextBox16.Value = firstrow
End Sub
As mentioned above, x = Me.TextBox6.Value 'enter any word or phrase finds only one word or phrase.
if Excel would accept something like Textbox6 = x = green tree #AND# red fish #OR# blue ink #AND# people will help you
and satisfy every one of these requests, that would solve the problem.

Can anyone help? I really appreciate it.

Thanks, cr
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Forgot to clarify in - in ONE Textbox, i.e., Textbox6 = x = green tree #AND# red fish #OR# blue ink #AND# people will help you
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top