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
Bookmarks