+ Reply to Thread
Results 1 to 7 of 7

Problem: Create multiple pivot tables from single source sheet

  1. #1
    Registered User
    Join Date
    01-02-2018
    Location
    Oslo, Norway
    MS-Off Ver
    2010/2017
    Posts
    20

    Problem: Create multiple pivot tables from single source sheet

    Hi,

    I have one source sheet with data and I want to create multiple pivot tables based on it with varying filters.

    This normally works fine, but when trying to create the same pivot table twice it causes this error: "Run-time error '5': Invalid procedure or argument"

    The debugger marks this line: Set pvt = Worksheets(SheetName).PivotTables.Add(pvtCache, Range(StartPvt), PivotName)

    I have tried deleting the worksheet containing the pivot table and then constructing it again, but it doesn't seem to help.

    Do you have some suggestion why this error is caused and how to prevent it?
    Last edited by maboho93; 03-01-2018 at 09:39 AM.

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Problem: Create multiple pivot tables from single source sheet

    If you delete the sheet containing the Pivot Table, the Pivot Cache also gets deleted. Make sure you create a new Pivot Cache before creating a new Pivot Table. And if you don't delete the Pivot Sheets, check if a Pivot Cache exists and use it as a source Pivot Cache in the Pivot Table creation otherwise create a new Pivot Cache first.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Problem: Create multiple pivot tables from single source sheet

    Hi,

    It would be useful to see more code. Are you trying to reuse the same name for another pivot table, or trying to put it over an existing pivot table?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Registered User
    Join Date
    01-02-2018
    Location
    Oslo, Norway
    MS-Off Ver
    2010/2017
    Posts
    20

    Re: Problem: Create multiple pivot tables from single source sheet

    Thank you for your answers. I worked around the problem by simply activating the sheet containing the pivot that I want instead of recreating it.

    I am wondering a bit about how the Pivot Cache works.
    This is what I am doing now: Set pvtCache = ActiveWorkbook.PivotCaches.Create(xlDatabase, RangeString) where RangeString is my source table for all pivot tables.

    Is it possible to use this to create multiple pivot tables with different names, based on exactly the same source?
    If it is not possible, how can I work it out?

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Problem: Create multiple pivot tables from single source sheet

    Yes- you should be able to use pvtCache.CreatePivotTable

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Problem: Create multiple pivot tables from single source sheet

    You can use PowerQuery to create different PivotTbles from the same single source

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Problem: Create multiple pivot tables from single source sheet

    If you want to create a Pivot Table based on Pivot Cache of an existing Pivot Table, try something like this...

    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. Macro to create Pivot Tables from data source of two Sheets
    By sameer79 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2018, 02:50 PM
  2. Multiple Pivot Tables with Data model - Source Problem
    By siva1612 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2016, 12:27 AM
  3. [SOLVED] create new pivot tables from same source in same tab
    By ammartino44 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-10-2014, 05:56 PM
  4. Several Pivot Tables from single source- design aid
    By eqlizr in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-11-2014, 09:28 AM
  5. Pivot Tables using multiple tables as a source
    By Chrisb1985 in forum Excel Charting & Pivots
    Replies: 26
    Last Post: 05-09-2014, 10:50 AM
  6. [SOLVED] Multiple Pivot Tables - Single table of source data
    By some_evil in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-09-2014, 11:56 PM
  7. Replies: 3
    Last Post: 02-27-2012, 08:03 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