Option Explicit
Sub TEST6()
Dim ar, br, cr, i&, j&, r&, k&, dic As Object, strJoin$
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = Sheets(1).[A1].CurrentRegion.Value
For i = 2 To UBound(ar)
strJoin = ar(i, 1) & "," & ar(i, 2)
dic(strJoin) = Array(ar(i, 3), ar(i, 4))
Next i
r = Cells(Rows.Count, "A").End(xlUp).Row
br = Range("A2:B" & r).Value
ReDim ar(1, 1)
For j = 0 To UBound(ar, 2)
Range(Cells(2, j * 8 + j + 4), Cells(r, j * 8 + j + 11)).Offset(1).Clear
Set ar(1, j) = Range(Cells(2, j * 8 + j + 4), Cells(r, j * 8 + j + 11))
ar(0, j) = ar(1, j).Value
Next j
For i = 2 To UBound(br)
strJoin = br(i, 1) & "," & br(i, 2)
If dic.exists(strJoin) Then
cr = dic(strJoin)
For j = 0 To 1
For k = 1 To UBound(ar(0, j), 2)
If ar(0, j)(1, k) = cr(j) Then
ar(0, j)(i, k) = cr(j)
ar(1, j).Cells(i, k).Interior.Color = vbRed
Exit For
End If
Next k
Next j
End If
Next i
For j = 0 To UBound(ar, 2)
For i = 1 To UBound(ar(0, j), 2)
r = 0
For k = 2 To UBound(ar(0, j))
If Len(ar(0, j)(k, i)) = False Then
r = r + 1
ar(0, j)(k, i) = r
Else
r = 0
End If
Next k
Next i
Cells(2, j * 8 + j + 4).Resize(UBound(ar(0, j)), UBound(ar(0, j), 2)) = ar(0, j)
Next j
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|