+ Reply to Thread
Results 1 to 9 of 9

Extract Data from Pivot Table with VBA

  1. #1
    Registered User
    Join Date
    03-26-2014
    Location
    Washington
    MS-Off Ver
    Excel 2010
    Posts
    61

    Extract Data from Pivot Table with VBA

    I have a Pivot Table (Pivot_Table_Report) on a sheet called "Summary" with a several fields (Name, Month, Area). I would like to be able to extract the data from the pivot table based on certain conditions for the fields given by the user in an input box and export it to a new workbook. For example, on the pivot table if you look at John for the name, July for the month, and North for the area it gives a total of 10. The user can then click a button and enter those same values into input boxes and get the data that makes up the 10 in a new workbook.
    I have looked all over and can't find a formula to use that incorporates more than one field. Any assistance would be appreciated! Thanks.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Extract Data from Pivot Table with VBA

    Why use formula? If you double click on value field, it will expand with underlying values in a new sheet.
    This can be emulated in code using Range.
    Ex:
    Please Login or Register  to view this content.
    You can then just export the sheet out to new workbook.

    However, how exactly you should code. Will depend on your pivot table set up (Filter, Slicers, Row/Column label etc).

    If you need more detailed help. I'd recommend that you upload sample workbook.
    Last edited by CK76; 07-26-2019 at 12:20 PM.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    03-26-2014
    Location
    Washington
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Extract Data from Pivot Table with VBA

    Thanks for the quick reply. I would like to prevent a user from accessing the actual pivot table itself. So they would not be able to double click on a field value to get the data. Also, I am not able to upload a file due to work restrictions at this time. I have the field value of 10 listed in another sheet, so the user can see that John in July had 10 for the North area. I would like them to be able to get the data that makes up the 10 without having to go to the pivot table. I currently have no filters on the pivot table itself. In addition, the cell address could change depending on the source data for the pivot table so the formula you posted above my not always work.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Extract Data from Pivot Table with VBA

    Code does the double clicking part for them

  5. #5
    Registered User
    Join Date
    03-26-2014
    Location
    Washington
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Extract Data from Pivot Table with VBA

    Thanks CK76. I'm not sure if you saw the last part of my reply but the cell address within the pivot table could alter depending on the data available.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Extract Data from Pivot Table with VBA

    Hence, need for sample workbook.

    Without it, we'd be stabbing at it in the dark.

    For an example if pivot table uses classic layout with repeated headers. It's much easier to find the cell that requires expanding.

    If it's in compact format. It becomes much more difficult to do so.

  7. #7
    Registered User
    Join Date
    03-26-2014
    Location
    Washington
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Extract Data from Pivot Table with VBA

    Ok thanks, makes sense. I'll see if I can get a sample together and post later. Appreciate the help

  8. #8
    Registered User
    Join Date
    03-26-2014
    Location
    Washington
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Extract Data from Pivot Table with VBA

    Another thought, and I'm not sure if this would be VBA or not. But is it possible to get the cell address from a GETPIVOTDATA result? If so I can use that to extract the data without the user having to go to the actual pivot table.

  9. #9
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Extract Data from Pivot Table with VBA

    Again, really depends on your set up.

    In most cases, GETPIVOTDATA isn't flexible enough and are usually replaced by Dynamic Named Ranges, User Defined Function etc.
    I've used it occasionally, but for the most part, I prefer OLAP based CUBE functions combined with DAX measures (which can't be used on traditional Pivots).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract Data from Pivot Table
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2019, 07:44 AM
  2. Extract pivot table data
    By bbertram in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-10-2015, 06:53 PM
  3. How to extract data of any specific day out of pivot table.
    By mir.mudassir in forum Excel General
    Replies: 1
    Last Post: 02-02-2015, 09:44 PM
  4. Extract data from sql and refresh the pivot table
    By zafirah in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-31-2013, 11:49 AM
  5. Extract data from Pivot Table
    By Skipper Jones in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-01-2012, 07:45 PM
  6. Extract ALL Pivot-Table Cache Data
    By TomJoad in forum Excel General
    Replies: 0
    Last Post: 01-14-2012, 10:37 AM
  7. Replies: 1
    Last Post: 05-24-2006, 01:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1