Jack-P-Winner
Member
Can you tell by my Macro which columns and rows are being searched? I presently gave my data I'm searching for in column C. I want to change it to search for data in a different column (R & V) How can I figure out what needs to be changed in this Macro? My workbook is too large to upload but I can shorten it if I have to. I basically have 30000 rows of numbers in C. I click on a button to select my range criteria of number sequence For example I want to find all the numbers the are in this specific order vertically 2-4-6-2-4-6-4-2. After I select the range it finds all the ones in C. I then click the next button for the next set of numbers
I've tried changing all the c's to an r or v but that didn't work.
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(y) <> -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
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
In the picture I can presently search for data in C. I want to add searching in R and V on the next sheet
Thanks Ninjas and Gurus
We need some common sense in the White house and eliminate all the politicians
I've tried changing all the c's to an r or v but that didn't work.
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(y) <> -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
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
In the picture I can presently search for data in C. I want to add searching in R and V on the next sheet
Thanks Ninjas and Gurus
We need some common sense in the White house and eliminate all the politicians