Sub x()
Dim rData As Range, vData, vData2, vData3(), n As Long, r As Long
Dim oDic1 As Object, oDic2 As Object
Application.ScreenUpdating = False
Set oDic1 = CreateObject("Scripting.Dictionary")
Set oDic2 = CreateObject("Scripting.Dictionary")
With Sheet1
.AutoFilterMode = False
.Range("A1").AutoFilter Field:=1, Criteria1:=.Range("J2").Value
.Range("A1").AutoFilter Field:=3, Criteria1:="<" & .Range("J1").Value
With .AutoFilter.Range
On Error Resume Next
Set rData = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rData Is Nothing Then
vData = rData.Value
Else
GoTo Err
End If
End With
Set rData = Nothing
.Range("A1").AutoFilter Field:=1, Criteria1:=.Range("J3").Value
With .AutoFilter.Range
On Error Resume Next
Set rData = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rData Is Nothing Then
vData2 = rData.Value
Else
GoTo Err
End If
End With
.AutoFilterMode = False
End With
ReDim vData3(1 To UBound(vData, 1) + UBound(vData2, 1), 1 To 3)
For r = LBound(vData, 1) To UBound(vData, 1)
If Not IsEmpty(vData(r, 2)) And Not oDic1.exists(vData(r, 2)) Then
n = n + 1
oDic1.Add vData(r, 2), n
End If
Next r
n = 0
For r = LBound(vData2, 1) To UBound(vData2, 1)
If Not IsEmpty(vData2(r, 2)) And Not oDic2.exists(vData2(r, 2)) Then
n = n + 1
oDic2.Add vData2(r, 2), n
End If
Next r
n = 0
For r = LBound(vData, 1) To UBound(vData, 1)
If oDic1.exists(vData(r, 2)) And oDic2.exists(vData(r, 2)) Then
n = n + 1
vData3(n, 1) = Sheet1.Range("J2") & "/" & Sheet1.Range("J3")
vData3(n, 2) = vData(r, 2)
vData3(n, 3) = vData(r, 3)
End If
Next r
If n = 0 Then GoTo Err
With Sheet2
.UsedRange.Clear
.Range("A1").Resize(n, 3) = vData3
End With
Err:
MsgBox "No points found"
Application.ScreenUpdating = True
End Sub
Bookmarks