+ Reply to Thread
Results 1 to 7 of 7

Changing source data on a Pivot table by VBA

  1. #1
    Registered User
    Join Date
    02-14-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    33

    Changing source data on a Pivot table by VBA

    Hi,

    I am trying to change the source data of some pivot tables using VBA. I have 22 Data sheets and each is in the same format, I want my pivot tables on my pivot table sheet "Dash 1" to change their source data based on a cell value (I.e."G38" shows Data 1, Data 2.... and I want to be the Sheet name that the source data is changed to).
    My Data Sheets are called Data 1: Data 22 and the name of the Sheet I want to change the source data to is in a cell in my sheet with the pivot tables.
    The source data is in columns A:AC rows 2 to 10,000

    So if G38= "Data 1" then the pivot tables in "Dash 1" show the data from "Data 1"...

    Hope you can help

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing source data on a Pivot table by VBA

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    02-14-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Changing source data on a Pivot table by VBA

    Hi Olly,

    Thanks for the help but I only want the pivot tables in sheet "Dash1" to update not all of the pivot tables in my workbook, any chance you could change the code for me?

    Cheers

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing source data on a Pivot table by VBA

    Quote Originally Posted by ZuneidDassu View Post
    Hi Olly,

    Thanks for the help but I only want the pivot tables in sheet "Dash1" to update not all of the pivot tables in my workbook, any chance you could change the code for me?

    Cheers
    Have a go. See what you think needs changed. Post your attempts, I'll help from there

  5. #5
    Registered User
    Join Date
    02-14-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Changing source data on a Pivot table by VBA

    Thank you Olly can I contact you tomorrow regarding the above as I am going to be out of the office for the rest of the day?

  6. #6
    Registered User
    Join Date
    02-14-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Changing source data on a Pivot table by VBA

    Hi Olly,

    I have managed to get it working using this:

    Please Login or Register  to view this content.
    There is probably a nicer way of doing it but it seems to work now.

    Thanks for your help

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing source data on a Pivot table by VBA

    There's lots of repetition in your code. My original code looped through every worksheet, then for every worksheet it looped through every pivot table.

    You only want to work with the pivot tables on one sheet, so we can take out the worksheet loop, but keep the pivot table loop. So it looks something like:
    Please Login or Register  to view this content.

+ 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] Changing Source Data for Pivot Chart/Table
    By zooropa33 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-18-2014, 12:41 AM
  2. Changing data source to update pivot table
    By jonesli in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-07-2014, 01:48 AM
  3. Changing Data source of a pivot table
    By ram-gopal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2012, 01:28 AM
  4. Changing the source data in a pivot table... how?
    By shadestreet in forum Excel General
    Replies: 1
    Last Post: 04-27-2007, 11:43 AM
  5. Changing Data Source for Pivot Table
    By jjj in forum Excel General
    Replies: 1
    Last Post: 04-13-2006, 04:40 AM

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