Hi,
I have amended the code below to give me a nearly desired pivot table.
Sub Pivot4()
Dim PTCache As PivotCache
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="Data!R1C1:R65536C15")
Set PT = PTCache.CreatePivotTable(TableDestination:="Pivot!R1C1", TableName:="PivotTable")
With PT.PivotFields("Account")
.Orientation = xlRowField
.Position = 1
End With
With PT.PivotFields("Description")
.Orientation = xlRowField
.Position = 2
End With
Sheets("Pivot").Select
With ActiveSheet.PivotTables("PivotTable").PivotFields("Rate")
.Orientation = xlDataField
.Position = 1
.Function = xlMin
.Name = "Min"
End With
With ActiveSheet.PivotTables("PivotTable").PivotFields("Rate")
.Orientation = xlDataField
.Position = 2
.Function = xlMax
.Name = "Max"
End With
End Sub
Firstly, I am trying to create two columns one for min rate and the other for max rate. I have tried adding columns for these but cannot seem to get it right, any help with this will be appreciated.
Secondly when the pivot table is formed each "account" has a subtotal. Is there something I can put in the code to switch this off for all totals?
Thanks in advance for any guidance.
I have amended the code below to give me a nearly desired pivot table.
Sub Pivot4()
Dim PTCache As PivotCache
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="Data!R1C1:R65536C15")
Set PT = PTCache.CreatePivotTable(TableDestination:="Pivot!R1C1", TableName:="PivotTable")
With PT.PivotFields("Account")
.Orientation = xlRowField
.Position = 1
End With
With PT.PivotFields("Description")
.Orientation = xlRowField
.Position = 2
End With
Sheets("Pivot").Select
With ActiveSheet.PivotTables("PivotTable").PivotFields("Rate")
.Orientation = xlDataField
.Position = 1
.Function = xlMin
.Name = "Min"
End With
With ActiveSheet.PivotTables("PivotTable").PivotFields("Rate")
.Orientation = xlDataField
.Position = 2
.Function = xlMax
.Name = "Max"
End With
End Sub
Firstly, I am trying to create two columns one for min rate and the other for max rate. I have tried adding columns for these but cannot seem to get it right, any help with this will be appreciated.
Secondly when the pivot table is formed each "account" has a subtotal. Is there something I can put in the code to switch this off for all totals?
Thanks in advance for any guidance.