Using VBA to get drill down data from a pivot table

Status
Not open for further replies.

MikexcelUK

New Member
Joined
Feb 11, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I am OK working with some VBA, so I can usually squash together different code to get what I need. I am no way an expert and usually rely on forums to find code that does what I need. I have searched for a solution to this and cant find anything...

I have a table of customer data (different utilities, usage, and amount some other fields) that is added to on a monthly basis. I edit the data through a pivot table and then using slicers which allow a particular customer, year and the month to be selected to return that month’s results (using getpivotdata formulas) - the selection of the month/year is to check prior months and trends. There are many different outputs I need, and I can get all of these using the getpivotdata formulas linked to cells (to make them dynamic) and put these into graphs and trends for people in my team to use to populate reports easily. These reports are on a linked worksheet, to the Pivot Table and working sheets are hidden.

The outputs have several fields which are volatile per customer (some may have more or less data (or none) each month). As a result, the pivot table size changes per customer selection (plus it gets wider each month).

Here is what I need:

What I would also like to be able to do is provide that month's underlying data for the chosen customer, plus the data per individual field, if/when that is needed for analysis.

Example: On the report page that is visible, I would have a button to download that month’s power data, another for the water data, one for the combined data, etc. All the drill down data can be selected by double clicking the appropriate cell in the Pivot Table. I can't record anything, because the recorded macro just refers to a cell reference, which changes with each customer selection and month (I only want this for the most recent month).

My thoughts are that I can have control cells automatically update with information pertaining to the pivot table headers and then have the code look at those cells to determine the drill down locations on the pivot table and then to extract that into a new sheet as usual.

I have searched high and low and cannot find anything to help… any ideas? Is this even possible?
 
Hi Amit,

I cannot share my file, because it contains real data - sorry.

If you review BSLAV's reply, that will explain how it works... essentially, if you use the =getpivot formula, then remove the redundant inverted commas (") in the VBA code, then it works
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
can't you share with the dummy data , meaning you can just alter your data with any abcd....z and then pivot macros should work as it is
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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