Sub test2()
Dim a, b, e, x, s(1) As String, dic As Object
Dim i As Long, ii As Long, iii As Long, iv As Long, n As Long, t As Long
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("results")
.UsedRange.Offset(1).Resize(, 13).ClearContents
Sheets("today").[a1].CurrentRegion.Resize(, 6).Copy .[a1]
Sheets("yesterday").[a1].CurrentRegion.Resize(, 6).Copy .[h1]
a = Intersect(.Columns("a:m"), .UsedRange)
For i = 2 To UBound(a, 1)
If a(i, 8) <> "" Then
s(0) = Join(Array(a(i, 9), a(i, 11)), Chr(2))
s(1) = Join(Array(a(i, 10), a(i, 11)), Chr(2))
dic(s(0)) = dic(s(0)) & IIf(dic(s(0)) <> "", ",", "") & i
dic(s(1)) = dic(s(1)) & IIf(dic(s(1)) <> "", ",", "") & i
End If
Next
ReDim b(1 To UBound(a, 1) * 2, 1 To UBound(a, 2))
For i = 2 To UBound(a, 1)
If a(i, 1) <> "" Then
n = n + 1: s(0) = Join(Array(a(i, 2), a(i, 4)), Chr(2))
s(1) = Join(Array(a(i, 3), a(i, 4)), Chr(2))
For ii = 1 To 6
b(n, ii) = a(i, ii)
Next
For ii = 0 To 1
If dic.exists(s(ii)) Then
x = Split(dic(s(ii)), ","): t = 0
For iii = 0 To UBound(x)
If a(x(iii), 8) <> "z" Then
For iv = 8 To UBound(a, 2)
b(n + t, iv) = a(x(iii), iv)
Next
a(x(iii), 8) = "z": t = t + 1
End If
Next
If dic.exists(s(0)) Then dic.Remove s(0)
If dic.exists(s(1)) Then dic.Remove s(1)
End If
Next
n = n + t - IIf(t, 1, 0)
End If
Next
If dic.Count Then
For Each e In dic
x = Split(dic(e), ",")
For i = 0 To UBound(x)
If a(x(i), 8) <> "z" Then
n = n + 1
For ii = 8 To UBound(a, 2)
b(n, ii) = a(x(i), ii)
Next
a(x(i), 8) = "z"
End If
Next
Next
End If
With .[a2].Resize(n, UBound(b, 2))
.Resize(UBound(a, 1)).ClearContents
.NumberFormat = "@"
.Value = b
.Columns("a:f").Borders.Weight = 2
.Columns("g:m").Borders.Weight = 2
.EntireColumn.AutoFit
.Parent.Select
End With
End With
Application.ScreenUpdating = True
End Sub
Bookmarks