Hello there,
Looking for some guidance on how to code into my macro adding a Pivot Table that has a variable data set.
I have the attached coding but does not work if the data set increases/decreases.
TIA!
Sub BuyerItemPivotTable()
'
' BuyerItemPivotTable Macro
'
'
Looking for some guidance on how to code into my macro adding a Pivot Table that has a variable data set.
I have the attached coding but does not work if the data set increases/decreases.
TIA!
Sub BuyerItemPivotTable()
'
' BuyerItemPivotTable Macro
'
'
VBA Code:
Range("B1:C1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"NReport!R1C2:R8431C3", Version:=6).CreatePivotTable TableDestination:= _
"Pivot Tables!R7C2", TableName:="PivotTable", DefaultVersion:=6
Sheets("Pivot Tables").Select
Cells(7, 2).Select
With ActiveSheet.PivotTables("PivotTable").PivotFields("Buyer Name")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable").AddDataField ActiveSheet.PivotTables( _
"PivotTable").PivotFields("Item Code"), "Count of Item Code", xlCount
End Sub