If not solved !! , Try this:-
Sub MG09Oct34
Dim Dn As Range
Dim temp As Integer
Dim Rng As Range
Dim nRng As Range
Dim Dic As Object
Dim k As Variant
Dim p As Variant
Dim c As Long
Sheets("Sheet2").Columns("A:A").MergeCells = False
With Sheets("Details")
Set Rng = .Range(.Range("A7"), .Range("A" & Rows.Count).End(xlUp))
End With
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
For Each Dn In Rng
If Not Dic.exists(Dn.Value) Then
Set Dic(Dn.Value) = CreateObject("Scripting.Dictionary")
End If
If Not Dic(Dn.Value).exists(Dn.Offset(, 1).Value) Then
Dic(Dn.Value).Add (Dn.Offset(, 1).Value), Dn
Else
Set Dic(Dn.Value).Item(Dn.Offset(, 1).Value) = Union(Dic(Dn.Value).Item(Dn.Offset(, 1).Value), Dn)
End If
Next Dn
c = 7
Sheets("Sheet2").Range("A6").Resize(, 5).Value = Array("Location", "Sold By", "Sum of Qty", "Sum of Cost", "Sum of MTD Cost")
For Each k In Dic.Keys
temp = c
With Sheets("Sheet2")
.Cells(c, "A") = k
For Each p In Dic(k)
.Cells(c, "B") = p
.Cells(c, "C") = Application.Sum(Dic(k).Item(p).Offset(, 2))
.Cells(c, "D") = Application.Sum(Dic(k).Item(p).Offset(, 3))
.Cells(c, "E") = Application.Sum(Dic(k).Item(p).Offset(, 4))
c = c + 1
Next p
With .Range("A" & temp).Resize(c - temp)
.MergeCells = True
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
End With
End With
Next k
MsgBox "Run"
End Sub
Regards Mick
Bookmarks