How to mimic a pivot table without a pivot table?

nutra

New Member
Joined
May 23, 2005
Messages
35
I have a list of items and their associated quantities, many items appearing multiple times. I need a concise list that summarizes each item and sums all of its quantities.

The obvious solution is a pivot table. However, I update this list frequently and for some reason the pivot table is difficult to update. is there a function or simple vba code that I could put into this workbook that would work better than my unflexible pivot table?

Thanks.
 
Still suggest using "Dictionary,test it please:
Code:
Sub mimicpiv2()
Application.ScreenUpdating = 0
Dim arr, i As Long, n As Long, t As Single, z As New Dictionary
t = Timer
n = [a65536].End(3).Row
arr = [a1].Resize(n, 2)
For i = 1 To n
z(arr(i, 1)) = z(arr(i, 1)) + arr(i, 2)
Next
n = z.Count
[h1].Resize(n, 2) = Application.Transpose(Array(z.keys, z.items))
[h2].Resize(n - 1, 2).Sort [h2]
Application.ScreenUpdating = 1
MsgBox Format(Timer - t, "0.000")
End Sub
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It's a bit faster because sorting of Raw data was not needed.
 
Upvote 0
Still suggest using "Dictionary,test it please:
Rich (BB code):
Dim arr, i As Long, n As Long, t As Single, z As New Dictionary
Unable to test it because my software won't recognize the part marked red.
It's a bit faster because sorting of Raw data was not needed.
Sorting raw data does not ipso facto (by reason of this fact alone) mean slower code. Depends on a number of other things, e.g. some alternatives might cause slower code than does the sorting procedure.

In the operational codes I've been able to test so far in this thread, the scripting dictionary and the sorting approach seem to give somewhat comparable run times. Depends on the data.

However, the Excel sort runs significantly faster on sorted, partially sorted, or even roughly ordered data than it does on completely randomized data, whereas it makes little difference to the scripting dictionary. And since it seems quite a lot of Excel data is at least roughly ordered in some way then ...
 
Upvote 0
Unable to test it because my software won't recognize the part marked red.Sorting raw data does not ipso facto (by reason of this fact alone) mean slower code. Depends on a number of other things, e.g. some alternatives might cause slower code than does the sorting procedure.

In the operational codes I've been able to test so far in this thread, the scripting dictionary and the sorting approach seem to give somewhat comparable run times. Depends on the data.

However, the Excel sort runs significantly faster on sorted, partially sorted, or even roughly ordered data than it does on completely randomized data, whereas it makes little difference to the scripting dictionary. And since it seems quite a lot of Excel data is at least roughly ordered in some way then ...


Add the dictionary object references by opening the project references from the Project menu and adding the Microsoft Scripting Runtime.

http://www.kamath.com/tutorials/images/tut009_vbref.gif
 
Upvote 0
All OK. That works fine.

Interesting coding. Your mimicry of pivot tables is effective.
 
Upvote 0
NorthWolves, sorry for the bump on an old post but this is almost exactly what I've been been trying to do for weeks now.

I tried your last bit of code from post #7, no scripting dictionary and it is very close.

What modifications would I need to do three columns, A, B, C and just display a count of the combinations for each ?
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top