As the title explains This code below works well enough if two variables x and y from two different textboxes are used:
I don't want two textboxes. I want to be able to type both values in one textbox
such as
Code:
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim cell As Range
Dim targetRow, lastrow As Long
Dim x, y As String
x = Textbox9.Value
y = Textbox10.Value
Set wsSource = ThisWorkbook.Sheets("Source") ' Change to your source sheet name
Sheets("Result").UsedRange.ClearContents
Set wsTarget = Sheets("Result") 'ThisWorkbook.Sheets.Add ' Creates a new sheet for the filtered data
targetRow = 1 ' Initialize the target row
For Each cell In wsSource.Range("E1:E31103") 'UsedRange
If InStr(1, cell.Value, x, vbTextCompare) > 0 And InStr(1, cell.Value, y, vbTextCompare) > 0 Then
cell.EntireRow.Copy wsTarget.Cells(targetRow, 1)
targetRow = targetRow + 1
End If
Next cell
MsgBox "Filtered data copied to Result sheet"
lastrow = Sheets("Result").Range("B" & rows.count).End(xlUp).Row
Me.TextBox3.Value = ListBox2.ListIndex + 1
Me.TextBox4.Value = lastrow
Sheets("Result").Range("H1").Value = lastrow
End Sub
[/ccode]
This line looks for the two variable values x and y from two different textboxes, Textbox9 and Textbox10.
[code]
If InStr(1, cell.Value, x, vbTextCompare) > 0 And InStr(1, cell.Value, y, vbTextCompare) > 0 Then...
such as
Code:
x = Textbox1.value if Textbox1.value = "sun [and] moon" , OR "green [and] tree"
and give the same result as having each value in two separate textboxes
I'm having a tough time figuring out how to change the InStr code line to do that
Any help would be appreciated.
cr