+ Reply to Thread
Results 1 to 4 of 4

Creating two pivot tables on same sheet - Optimize recorded macro code

  1. #1
    Registered User
    Join Date
    07-09-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    8

    Creating two pivot tables on same sheet - Optimize recorded macro code

    Hi all,
    I am trying to record a macro to create two pivot tables on the same sheet.
    I need your suggestions to optimize the code.
    Also, there are two issues that I'll like to get sorted out
    1. The macro always throws an error at the point where the pivot table is being inserted.
    2. The number of rows vary every month and I don't know how to optimize the code to accordingly.

    Please find attached the raw data and code for your reference.
    Please Login or Register  to view this content.
    Thanks and regards,
    johnny_tc
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Creating two pivot tables on same sheet - Optimize recorded macro code

    Hi, johnny_tc,

    you use the constants PivotTable8 and PivotTable9 for thenames of the pivot tables. As long as these pivot tables still are in the workbook an exception should be trhown up.

    Alternative: use constants for the names of the pivottables and alter the code where the old constants are used.

    Regarding the varying ranges of data:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  3. #3
    Registered User
    Join Date
    07-09-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Creating two pivot tables on same sheet - Optimize recorded macro code

    Thanks a lot Holger. I will have a look at this code and will let you know of the progress.

    Meanwhile there is one more issue that I'm facing.
    While trying to insert the second pivot table, it is automatically taking the Grand Totals at the bottom.
    Is there any way to avoid this while inserting the second pivot???

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Creating two pivot tables on same sheet - Optimize recorded macro code

    Hi, johnny_tc,

    first of all the sheetname should be altered to "'Raw Data'" instead of "Raw Data".

    Second: if you know the name of the PT as you have passed it in (like in the example):

    Please Login or Register  to view this content.
    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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