+ Reply to Thread
Results 1 to 7 of 7

Pivot Table Macro Needed

Hybrid View

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

    Re: Pivot Table Macro Needed

    Nope - you need to include headers for the pivot table to use as field names. So:

        Dim LR1                   As Long
        Dim PT                    As PivotTable
    
        LR1 = Range("A" & Rows.Count).End(xlUp).Row - 1
    
        Set PT = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
                    "Report1!R1C1:R" & LR1 & "C17").CreatePivotTable(TableDestination:=Sheets.Add.Cells(1, 3), _
                    DefaultVersion:=xlPivotTableVersion10)
    
        With PT
            .AddFields RowFields:=Array("Imprint", "DAC Market", "Data")
            With .PivotFields("Net Val")
                .Orientation = xlDataField
                .Position = 1
            End With
            With .PivotFields("Margin")
                .Orientation = xlDataField
                .Position = 2
            End With
            With .PivotFields("Home Return")
                .Orientation = xlDataField
                .Caption = "Sum of Home Return"
                .Function = xlSum
            End With
            With .DataPivotField
                .Orientation = xlColumnField
                .Position = 1
            End With
        End With
    Note I changed the C18 to C17 since you said column Q, not R.
    Everyone who confuses correlation and causation ends up dead.

  2. #2
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    424

    Re: Pivot Table Macro Needed

    Hi romperstomper,

    This works almost perfectly. How can i make the pivot table start in A1 of the new sheet? It is spread across C:G.

    Regards

    Tim

+ 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. complex macro needed for pivot table
    By Exceler54 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-08-2014, 01:18 PM
  2. Macro Help Needed - Link Pivot Table Filter to Regular Table AutoFilter
    By ycx1129 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2011, 12:54 PM
  3. Macro needed for pivot table
    By PlanetGong in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-13-2009, 05:55 PM
  4. Help needed with Pivot table macro to remove data
    By Nelly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2006, 09:00 PM
  5. [SOLVED] Macro Needed for Pivot Table
    By douglascfast@hotmail.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2005, 12:10 PM

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