+ Reply to Thread
Results 1 to 2 of 2

Problem with a recorded macro to create two pivot tables from same data

  1. #1
    Pete Straman via OfficeKB.com
    Guest

    Problem with a recorded macro to create two pivot tables from same data

    All:

    I recorded a macro to create two pivot tables. I create the second table by
    copying the first, moving over two columns, paste the data, and them go
    into the layout to change the data and column fields.
    When I run the macro it gives me a run time error listed below. How do I
    change the code to create the second table and fields like I did when I
    record it?

    Columns("A:B").Select
    Selection.Copy
    Range("C1").Select
    ActiveSheet.Paste
    Range("C7").Select
    Application.CutCopyMode = False
    ActiveSheet.PivotTableWizard TableDestination:="Sheet1!R1C3"

    ********* Problem starts here *************

    Run-time error ‘1004-:
    Unable to get the PivotTables property of the worksheet class

    ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:="dosmoyr", _
    ColumnFields:="transmoyr", PageFields:="facilityid"
    ActiveSheet.PivotTables("PivotTable2").PivotFields("Revenue").Orientation =
    _
    xlHidden
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Sum of
    Payments")
    .Orientation = xlDataField
    .Caption = " Payments"
    .NumberFormat = "#,##0.00_);(#,##0.00)"
    End With
    ActiveSheet.PivotTables("PivotTable2").DataPivotField.PivotItems("
    Payments"). _
    Position = 1


    C. Pete Straman

    --
    Message posted via http://www.officekb.com

  2. #2
    Jim Thomlinson
    Guest

    RE: Problem with a recorded macro to create two pivot tables from same

    You are better off to create 2 tables from scratch. If you just copy the
    first and paste it, the pivot cache data will be the same and changes made to
    one table will be replicated in the other. Probably not what you want...

    HTH

    "Pete Straman via OfficeKB.com" wrote:

    > All:
    >
    > I recorded a macro to create two pivot tables. I create the second table by
    > copying the first, moving over two columns, paste the data, and them go
    > into the layout to change the data and column fields.
    > When I run the macro it gives me a run time error listed below. How do I
    > change the code to create the second table and fields like I did when I
    > record it?
    >
    > Columns("A:B").Select
    > Selection.Copy
    > Range("C1").Select
    > ActiveSheet.Paste
    > Range("C7").Select
    > Application.CutCopyMode = False
    > ActiveSheet.PivotTableWizard TableDestination:="Sheet1!R1C3"
    >
    > ********* Problem starts here *************
    >
    > Run-time error ‘1004-:
    > Unable to get the PivotTables property of the worksheet class
    >
    > ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:="dosmoyr", _
    > ColumnFields:="transmoyr", PageFields:="facilityid"
    > ActiveSheet.PivotTables("PivotTable2").PivotFields("Revenue").Orientation =
    > _
    > xlHidden
    > With ActiveSheet.PivotTables("PivotTable2").PivotFields("Sum of
    > Payments")
    > .Orientation = xlDataField
    > .Caption = " Payments"
    > .NumberFormat = "#,##0.00_);(#,##0.00)"
    > End With
    > ActiveSheet.PivotTables("PivotTable2").DataPivotField.PivotItems("
    > Payments"). _
    > Position = 1
    >
    >
    > C. Pete Straman
    >
    > --
    > Message posted via http://www.officekb.com
    >


+ 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