I have this macro that finds data searching rows. I have to hit next for it to find the next set if same data I would like the ability for it to paste all the data it finds on the next sheet
Currently I have to stop the search to copy and paste data and then start all over again. Plus it is VERY time consuming to look at patterns and as y'all know time between draws is crucial for yes to have our data like now lol
Here is the macro and I'll upload a spreadsheet soon. I'm on my iPad and not sure I can from here
Sub test() Dim myPtn As Range, r As Range, x, myTxt, mymatch As Range
Dim ff As String, i As Long, y, flg As Boolean, myAreas As Areas
Dim Match
Columns("c:e").Borders.LineStyle = xlNone
Columns(6).ClearContents
Set myAreas = Application.InputBox("Select the pattern range(s)", Type:=8).Areas
For Each myPtn In myAreas
myTxt = myPtn(1).Value
Set r = Columns(3).Find(myTxt, , , 1)
If Not r Is Nothing Then
ff = r.Address
Do
x = Evaluate(r.Resize(myPtn.Rows.Count, 2).Address & "=" & myPtn.Address)
For i = 1 To 2
y = Filter(Application.Transpose(Application.Index(x, 0, i)), False)
If UBound <> -1 Then flg = True: Exit For
Next
If Not flg Then
If mymatch Is Nothing Then
Set mymatch = r.Resize(myPtn.Rows.Count, 3)
Else
Set mymatch = Union(mymatch, r.Resize(myPtn.Rows.Count, 3))
End If
r.Resize(myPtn.Rows.Count, 3).BorderAround Weight:=xlThick
r.Offset(, 3).Value = "x"
End If
Set r = Columns(3).FindNext(r): flg = False
Loop Until ff = r.Address
End If
Next
MsgBox IIf(mymatch Is Nothing, "No match", Replace(mymatch.Address, ",", vbLf)), _
, IIf(mymatch Is Nothing, "Not ", "") & "Found"
If Not mymatch Is Nothing Then mymatch.Select
End Sub
VB:
Private Sub CommandButton1_Click()
Dim c
Dim firstAddress As String
With Worksheets("Filter").Range("F2", Range("F" & Rows.Count).End(xlUp))
Set c = .Find("x", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(, -3).Resize(1, 3).Select
Set c = .FindNext(c)
If MsgBox("Next Match?", vbYesNo) = vbNo Then Exit Sub
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
Currently I have to stop the search to copy and paste data and then start all over again. Plus it is VERY time consuming to look at patterns and as y'all know time between draws is crucial for yes to have our data like now lol
Here is the macro and I'll upload a spreadsheet soon. I'm on my iPad and not sure I can from here
Sub test() Dim myPtn As Range, r As Range, x, myTxt, mymatch As Range
Dim ff As String, i As Long, y, flg As Boolean, myAreas As Areas
Dim Match
Columns("c:e").Borders.LineStyle = xlNone
Columns(6).ClearContents
Set myAreas = Application.InputBox("Select the pattern range(s)", Type:=8).Areas
For Each myPtn In myAreas
myTxt = myPtn(1).Value
Set r = Columns(3).Find(myTxt, , , 1)
If Not r Is Nothing Then
ff = r.Address
Do
x = Evaluate(r.Resize(myPtn.Rows.Count, 2).Address & "=" & myPtn.Address)
For i = 1 To 2
y = Filter(Application.Transpose(Application.Index(x, 0, i)), False)
If UBound <> -1 Then flg = True: Exit For
Next
If Not flg Then
If mymatch Is Nothing Then
Set mymatch = r.Resize(myPtn.Rows.Count, 3)
Else
Set mymatch = Union(mymatch, r.Resize(myPtn.Rows.Count, 3))
End If
r.Resize(myPtn.Rows.Count, 3).BorderAround Weight:=xlThick
r.Offset(, 3).Value = "x"
End If
Set r = Columns(3).FindNext(r): flg = False
Loop Until ff = r.Address
End If
Next
MsgBox IIf(mymatch Is Nothing, "No match", Replace(mymatch.Address, ",", vbLf)), _
, IIf(mymatch Is Nothing, "Not ", "") & "Found"
If Not mymatch Is Nothing Then mymatch.Select
End Sub
VB:
Private Sub CommandButton1_Click()
Dim c
Dim firstAddress As String
With Worksheets("Filter").Range("F2", Range("F" & Rows.Count).End(xlUp))
Set c = .Find("x", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(, -3).Resize(1, 3).Select
Set c = .FindNext(c)
If MsgBox("Next Match?", vbYesNo) = vbNo Then Exit Sub
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub