+ Reply to Thread
Results 1 to 4 of 4

Pivot Table Column Names

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Pivot Table Column Names

    When I record the creation of a pivot table, and choose for my data source columns A:D, the code recorded for the column selection is similar to this, showing C for columns 1-4:
    ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
            "'Summary View'!C1:C4"
    I then put that same code back into my macro, looking like this:
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
            "'Summary View'!C1:C4").CreatePivotTable TableDestination:= _
            "'[Regional CPS (Put in Date) Filled Compared to Target-Full.xls]Summary View'!R1C16" _
            , TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    However, when I run my macro, instead of the source being Columns 1-4, the source is column c, rows 1-4. How do I tell my macro I want columns 1-4?

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Pivot Table Column Names

    Let me rephrase, so maybe someone can steer me in the right direction:

    When I RECORD the creation of a pivot table, and I select columns A-D as my source, the code recorded for that selection is:
    "'Summary View'!C1:C4"
    When I PLAY BACK the macro, "'Summary View'!C1:C4" is interpreted as Column C, rows 1-4.

    That's a problem for me, and I don't know how to overcome it.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Pivot Table Column Names

    Specify the rows. You should not use entire columns for pivot tables.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Pivot Table Column Names

    Okay, so I'd have to include a "lastrow" variable. How do I write my range in creating the pivot? Something like this?
    "'Summary View'!A1:D" & LastRow

+ 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