Title explains
This code works well enough but only finds one variable value of all the cells with the word"green"
I want the code to find all the cells with the twords "green" AND "tree". They can be separated and not be a phrase.
The code would find this cell that contains "there is a green apple on every tree" as well as "there are many green trees on this street".
Any help would greatly be appreciated,
Thanks, cr
This code works well enough but only finds one variable value of all the cells with the word"green"
I want the code to find all the cells with the twords "green" AND "tree". They can be separated and not be a phrase.
The code would find this cell that contains "there is a green apple on every tree" as well as "there are many green trees on this street".
Code:
Dim x as string
x = "green"
Sheets("VALSFOUND").UsedRange.ClearContents
Dim lastrow, LastRow2 As Integer, X As String, C As Range, rw As Long, firstAddress As Variant, rowno As Variant, RownoA As Variant
X = Textbox1.value
With Worksheets("SOURCE").Range("C1:C31103") 'default NASB
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("SOURCE").Select 'copy all the found values to sheet VALSFOUND
C.Select
Range(Cells(C.Row, 2), Cells(C.Row, 7)).Copy Destination:=Sheets("VALSFOUND").Range("A" & rw) '
rw = rw + 1
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress
lastrow = Sheets("VALSFOUND").Range("A" & rows.count).End(xlUp).Row
If lastrow = 1 Then
Range(Cells(C.Row, 2), Cells(C.Row, 7)).Copy Destination:=Sheets("VALSFOUND").Range("A" & rw)
Else
Range(Cells(C.Row, 2), Cells(C.Row, 7)).Copy Destination:=Sheets("VALSFOUND").Range("A" & lastrow)
End If
Else
MsgBox "value not found"
End If
End With
Thanks, cr