Hmmm, OK maybe I'll give that a try.
To be honest from an output perspective the current methodology gives the ideal result. But if it's that difficult I'll look for another solution.
Hmmm, OK maybe I'll give that a try.
To be honest from an output perspective the current methodology gives the ideal result. But if it's that difficult I'll look for another solution.
Try this :-
Results sheet2 from Data on sheet1
Regards MickSub MG05May43 Dim Rng As Range, Dn As Range, n As Long, c As Long Dim Q As Variant With Sheets("Sheet1") Set Rng = .Range(.Range("A1"), .Range("A" & Rows.Count).End(xlUp)) End With ReDim Ray(1 To Rng.Count, 1 To 3) Ray(1, 1) = "Item Code": Ray(1, 2) = "Total": Ray(1, 3) = "Name" n = 1 With CreateObject("scripting.dictionary") .CompareMode = vbTextCompare For Each Dn In Rng If Not .Exists(Dn.Value) Then n = n + 1 Ray(n, 1) = Dn.Value: Ray(n, 2) = Dn.Offset(, 1).Value Ray(n, 3) = Dn.Offset(, 2).Value .Add Dn.Value, Array(n, 3, Dn.Offset(, 2).Value) Else Q = .Item(Dn.Value) Ray(Q(0), 2) = Ray(Q(0), 2) + Dn.Offset(, 1).Value If InStr(Q(2), Dn.Offset(, 2).Value) = 0 Then Q(1) = Q(1) + 1 If UBound(Ray, 2) < Q(1) Then ReDim Preserve Ray(1 To Rng.Count, 1 To Q(1)) Ray(Q(0), Q(1)) = Dn.Offset(, 2).Value Ray(1, Q(1)) = "Name" End If .Item(Dn.Value) = Q End If Next c = .Count End With With Sheets("Sheet2").Range("A1").Resize(c + 1, UBound(Ray, 2)) .Value = Ray .Columns.AutoFit End With MsgBox "Run" End Sub
Thanks MickG - I'll give that a go!
Hi !
First idea is to still use an advanced filter but you already have a code …
So try this demonstration using an array variable as a dictionary (Data row #1 is columns titles) :
PHP Code:
Sub Demo1()
Const DATA = "Data", SR = ", "
VA = Worksheets(DATA).Cells(1).CurrentRegion
ReDim DK$(1 To UBound(VA), 0), DS(1 To UBound(VA), 1 To 2)
For R& = 2 To UBound(VA)
V = Application.Match(VA(R, 1), DK, 0)
If IsError(V) Then
L& = L& + 1: DK(L, 0) = VA(R, 1): DS(L, 1) = VA(R, 2): DS(L, 2) = VA(R, 3)
Else
DS(V, 1) = DS(V, 1) + VA(R, 2)
If InStr(SR & DS(V, 2) & SR, SR & VA(R, 3) & SR) = 0 Then DS(V, 2) = DS(V, 2) & SR & VA(R, 3)
End If
Next
With Worksheets("Summary")
.UsedRange.Clear
Worksheets(DATA).[A1:C1].Copy .Cells(1)
With .[A2].Resize(L, 3)
.Columns(1).Value = DK
Worksheets(DATA).[B2].Copy: .Columns(2).PasteSpecial xlPasteFormats
.Columns("B:C").Value = DS
.Columns(3).AutoFit
End With
Application.CutCopyMode = False: Application.Goto .Cells(5)
End With
End Sub
Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
Last edited by Marc L; 05-06-2015 at 04:44 AM. Reason: optimizing …
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks