Results 1 to 7 of 7

add a column (sort column) in vba pivot table

Threaded View

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    add a column (sort column) in vba pivot table

    I am very unversed in the magic of pivot tables ( never got one to work how I wanted it to), but with assistance from here have a pivot table output that saves much time.

    A change in reporting format has led to a requirement to catagorise the pivot table data by county. At present it takes and sorts by a column "Waste Facility" and sums totals of actual weights.

    I need to utilise a column in the data range "County" and add that to the pivot output so that the data is then sorted by county.

    Code for pivot table as is
            Set dataSheet = .Sheets("Sheet1")
            Set sht = .Sheets.Add(After:=dataSheet)
            sht.Name = "PivotSheet"
            SrcData = "'" & dataSheet.Name & "'!" & _
                    dataSheet.Range("n1:p" & Lrow).Address(ReferenceStyle:=xlR1C1)  ''''''''''''''column for county is "G"
            GWT = Application.Sum(dataSheet.Range("o2:o" & Lrow))
            Set StartPvt = sht.Range("a3")
            Set pvtCache = .PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SrcData)
        End With
            
            Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="Tab_1_Return")
            Application.CommandBars("PivotTable").Visible = False
            
            With pvt
                .PivotFields("Waste Facility").Orientation = xlRowField
                '.AddDataField .PivotFields("County")
                .AddDataField .PivotFields("Actual Weight"), "Total weight", xlSum
                
                .ShowTableStyleRowStripes = True
            End With
    Any pointers appreciated
    Last edited by nigelog; 01-24-2019 at 07:07 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sort pivot table by second column
    By jdfjab in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-10-2017, 04:39 PM
  2. Pivot Table: Two-column sort ?
    By Dave+ in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 09-20-2017, 06:50 AM
  3. [SOLVED] Sort Pivot Table by Column Subtotal
    By Tayque_J_Holmes in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-20-2016, 02:08 PM
  4. [SOLVED] Need to sort pivot table's column labels by type
    By adelkam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2015, 03:27 AM
  5. VBA to Sort Pivot Table (Specific Column)
    By AHFoddeR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 02:39 AM
  6. Replies: 0
    Last Post: 11-11-2011, 04:10 PM
  7. [SOLVED] Sort a Column of Dates in Pivot Table
    By Linny in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-22-2005, 09:05 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