+ Reply to Thread
Results 1 to 3 of 3

Copying Pivot

  1. #1
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Copying Pivot help !!

    Hi,

    I've recorded adding one pivot table and then copying it 4 times and changing some info.

    The code below remembers the old Pivot Table no 11. How do I get it to use the next un-used Pivot table no ??

    ActiveSheet.PivotTables("PivotTable11").PivotFields("Source").CurrentPage = _
    "P. YR"

    Any help appreciated

    VBA Noob

  2. #2
    Debra Dalgleish
    Guest

    Copying Pivot

    You can use variables to identify each pivot table as you create it. For
    example:

    '=============================
    Sub CopyPivot()
    Dim ws1 As Worksheet
    Dim pc As PivotCache
    Dim pt1 As PivotTable
    Dim pt2 As PivotTable

    Set ws1 = Worksheets("Sheet1")
    Set pc = ActiveWorkbook.PivotCaches.Add(xlDatabase, _
    SourceData:="PivotData")
    Set pt1 = pc.CreatePivotTable(TableDestination:=ws1.Range("A3"), _
    TableName:="SalesPivot1")

    With pt1
    .AddFields RowFields:="Region"
    .PivotFields("Units").Orientation = xlDataField
    With .PivotFields("Item")
    .Orientation = xlPageField
    .Position = 1
    End With
    End With

    pt1.TableRange2.Copy Destination:=ws1.Range("F1")
    Set pt2 = ws1.Range("F1").PivotTable
    pt2.PivotFields("Item").CurrentPage = "Desk"

    End Sub
    '==============================

    VBA Noob wrote:
    > Hi,
    >
    > I've recorded adding one pivot table and then copying it 4 times and
    > changing some info.
    >
    > The code below remembers the old Pivot Table no 11. How do I get it to
    > use the next un-used Pivot table no ??
    >
    > ActiveSheet.PivotTables("PivotTable11").PivotFields("Source").CurrentPage
    > = _
    > "P. YR"
    >
    > Any help appreciated
    >
    > VBA Noob
    >
    >



    --
    Debra Dalgleish
    Contextures
    http://www.contextures.com/tiptech.html


  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Thanks Debra

    VBA Noob

+ 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