VBA Pivot Table Array?

jimsjams

New Member
Joined
Nov 6, 2008
Messages
29
Hi there,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
I was wondering whether anybody knew whether it is possible to use an array to choose which pivot items to select.
<o:p> </o:p>
I have a pivot table which contains thousands of pivot items (‘sell codes’), but I would like to select only a few hundred. As I am going to have to do this daily (and the ones I am looking for might change each day) I’d like to be able to fill an array with the relevant ‘sell codes’ and get the pivot table to only display these.
<o:p> </o:p>
Is this possible using an array to populate the pivot items?
<o:p> </o:p>
If not – can you think of a better way of only displaying certain pivot field items without having to either select them from the drop down box on the pivot table or manually write the .pivotitems(“example1”).visible=true vba line for each one I want to see?
<o:p> </o:p>
Thanks very much for any thoughts,
<o:p> </o:p>
James
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi, Jim.

Maybe have a new table with the list of sell codes you want to see? Then put an extra column in the source data and call it "ShowIt". Populate with a formula to return TRUE or FALSE if the selll code for that record is in the new list of sell codes. Such as =ISNUMBER(MATCH(sell code, new list, 0)) Make this new field a page field in the pivot table (and set it to TRUE).

It can also be done without adding the extra column to the data but is a little more complex - such as create the pivot table via the external data option and use SQL to do the work. Such as below. Untested.

Code:
SELECT BT.*
FROM BigTable BT, NewTable NT
WHERE BT.`sell code` = NT.`sell code`
This SQL is a rough guide, if you want to take this option, you might need to post some more details. With this approach the pivot table will only have the records for which the `sell codes` are in the list of codes you want.

There are other ways via VBA but the above should be adequate.

Regards, Fazza
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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