Try this:-
Your actual data assumed to start "A2".
Result start "E1".
Sub MG23Apr23
Dim Rng As Range, Dn As Range, n As Long, Q As Variant, Ac As Long, c As Long
Dim nRay()
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not .Exists(Dn.Value) Then
ReDim Ray(1 To Rng.Count, 1 To 2)
Ray(1, 1) = Dn.Offset(, 1).Value
Ray(1, 2) = Dn.Offset(, 2).Value
.Add Dn.Value, Array(Ray, 1)
Else
Q = .Item(Dn.Value)
Q(1) = Q(1) + 1
Q(0)(Q(1), 1) = Dn.Offset(, 1).Value
Q(0)(Q(1), 2) = Dn.Offset(, 2).Value
.Item(Dn.Value) = Q
End If
Next
Dim K As Variant, p As Variant
For Each K In .Keys
If .Item(K)(1) < 8 Then
For Ac = 1 To 8 - .Item(K)(1)
c = c + 1
ReDim Preserve nRay(1 To 3, 1 To c)
nRay(1, c) = K
nRay(2, c) = .Item(K)(0)(1, 1)
nRay(3, c) = .Item(K)(0)(1, 2)
Next Ac
End If
For n = 1 To .Item(K)(1)
c = c + 1
ReDim Preserve nRay(1 To 3, 1 To c)
nRay(1, c) = K
nRay(2, c) = .Item(K)(0)(n, 1)
nRay(3, c) = .Item(K)(0)(n, 2)
Next n
Next K
End With
Range("E1").Resize(c, 3) = Application.Transpose(nRay)
End Sub
Regards Mick
Bookmarks