+ Reply to Thread
Results 1 to 2 of 2

VBA Code for Multiple sheet Pivot Table Data copy and paste to another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    11-14-2014
    Location
    Abohar
    MS-Off Ver
    2010
    Posts
    1

    VBA Code for Multiple sheet Pivot Table Data copy and paste to another sheet

    I'm trying to create a macro that will copy multiple pivot tables side by side with varying length (or rows) on more than one worksheet in a workbook, and paste them one after another onto a new worksheet within that workbook.

    The pivot tables have the same number of columns from the different data source and are filtered based on certain criteria that vary among each pivot table.
    The reason I want to copy each pivot table to a worksheet is because I want to compare the collective data from the pivot tables to all of the data from the data source to capture any data that may not appear on the pivot tables (to catch any exceptions).

    I know I can cut and paste the data from the pivot tables and compare to the data source to get what I need, but I am hoping to avoid having to cut and paste the data from each pivot table. That's where the macro/vba I am looking for would be helpful.

    i came across below code which is working perfectly but the issue is that it paste the pivot tables it self not data of table, so i am not able to do any thing over it .

    what i need is that it should paste the values and formatting instead of table

    below is the code :
    Sub Test()
    
        'Makes code run faster
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        
        'For Regular OD PTP
        For i = 1 To 1
            LR = Sheets("Test").Range("A" & Rows.Count).End(xlUp).Row
                
            Sheets("Regular OD PTP").Activate
            
            Sheets("Regular OD PTP").PivotTables("PivotTable" & i).PivotSelect "", xlDataAndLabel, False
                Selection.Copy
            Sheets("Test").Activate
                Sheets("Test").Range("A" & LR + 2).Select
                ActiveSheet.Paste
        Next i
        
        'For OLD OD PTP pivot Sheet
        For i = 6 To 6
            LR = Sheets("Test").Range("A" & Rows.Count).End(xlUp).Row
                
            Sheets("OLD OD PTP pivot").Activate
            
            Sheets("OLD OD PTP pivot").PivotTables("PivotTable" & i).PivotSelect "", xlDataAndLabel, False
                Selection.Copy
            Sheets("Test").Activate
                Sheets("Test").Range("A" & LR + 2).Select
                ActiveSheet.Paste
        Next i
        
        'Formatting pivot tables for column adjustment
        numCol = Sheets("Test").UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
        letcol = Replace(Cells(1, numCol).Address(False, False), "1", "")
        
        Sheets("Test").Activate
        
        ActiveSheet.Columns("A:" & letcol).AutoFit
            
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        
    End Sub
    Please Help

    Neeraj

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,800

    Re: VBA Code for Multiple sheet Pivot Table Data copy and paste to another sheet

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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. VBA to Copy Data from multiple Pivot table in one sheet
    By winmaxservices in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-28-2019, 03:46 PM
  2. Copy cell from one sheet, find coresponding date on 2nd sheet data table, paste value
    By Soccer0228 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2019, 01:14 PM
  3. Replies: 0
    Last Post: 02-28-2018, 05:39 PM
  4. need vba code to copy pivot table and paste into Master sheet end row
    By johnlara in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2016, 03:59 PM
  5. VBA code to put a pivot and copy paste the data on a other sheet
    By aravindkm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2013, 12:07 PM
  6. [SOLVED] VBA Code to copy data from one sheet and paste to multiple other sheets
    By JimmyG. in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2013, 04:25 AM
  7. Replies: 1
    Last Post: 03-28-2013, 02:49 PM

Tags for this Thread

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