VB and Pivot Tables

velohead

Board Regular
Joined
Aug 22, 2007
Messages
212
Hi All,

I'm using Excel 2003

I have a spreadsheet where I frequently....
delete a particular pivot table
then recreate the same pivot table.

Can I automate the pivot table creation using VB ?
The data is contiguous, and the pivot table is very simple..
columns = months
rows = descriptions
values = amounts

Thanks
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Can I ask why you are deleting the PivotTable and then recreating it? What is the purpose behind doing that?
 
Upvote 0
deleting and recreating the pivot because...

a) if any details are changed within the source data, such as changing a description or category, then when the pivot is refreshed these 'new' items then appear at the bottom.
I prefer alphabetical order, so i guess i would have to do some sort of data sort, which I have not tried to do as yet.

b) also, the source data area may get longer, as new months are appended to the data.


As the pivot is so simple, I thought this might be the way to go, depending on how easy the code may be, of course.
 
Last edited:
Upvote 0
Use a dynamic name for the source ... then as new data is appended it will get picked up on refresh.

And then sort the pivottable. That is a one click operation.
 
Upvote 0
Sounds good to me, and I'll try them.
But how do I do each, please.

Is setting up a dynamic name a bit like ODBC, or more like a named area ?

Is data sort one click, I can only see.. "move up / move down etc" under the Order option when Right Click.

NB - using Excel 2003
 
Upvote 0
A dynamic name is a defined name that contains a formula to return a range. Do Insert/Name/Define, choose a name of PivotSource, and have a definition like:
=OFFSET($A$1,0,0,COUNTA($A:$A),12)

adjusting references and width (I've specified 12 columns ) to your case.

As for sorting, select a field cell, and press a Sort button ( if I remember rightly, you should have those on one of your main toolbars ).
 
Upvote 0
Sort Data - wow, that works like an absolute dream.
Literally two mouse clicks, and the pivot is perfect (ie alpha order).
I did not know one could do that, in that way.
Thank You.
 
Upvote 0
Dynamic Name - Think i am struggling on this.

I have created a 'named area' using..."Do Insert/Name/Define, choose a name of PivotSource, and have a definition like: =OFFSET($A$1,0,0,COUNTA($A:$A),12)"

But what next ?

One can see a 'named area' in the drop down field, just above column A or B.
But this 'PivotSource' is not in the drop down field, but it does exist, I can see it via Insert/Name/Define.
 
Upvote 0
A dynamically defined range name does not appear in the names drop down ... that is expected. You specify the name as the input range for the PivotTable, that's what the name is for.
 
Upvote 0
Thanks GlennUK, it is now working ok, in that the pivot is now created using PivotSource.

Should work a dream when I do the month-end stuff.
Thanks for your time on this.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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