Remove all column and row fields from a pivot table

T

takuto.yamada

I know how to add a field (see below) to a pivot table, but from a
state where I don't know which columns and rows are added to the pivot
table, how can I "reset" the pivot table so I can add only the fields
I'm interested in?

Sheet1.PivotTables("PivotTable8").AddFields
RowFields:="Customer", _
ColumnFields:="CloseQuarter"
With Sheet22.PivotTables("PivotTable8").PivotFields("Sales")
.Orientation = xlDataField
.Function = xlSum
.Position = 1
End With
 
M

marcus

Hi Takuto

This will remove all the items in your pivot table so you have a blank
table. Ready to populate with new information.

Take care

Marcus

Sub RemovePTItems()
'Removes all items in pivot table
Dim pt As PivotTable
Dim i As Integer

Set pt = ActiveSheet.PivotTables(1)
i = pt.PivotFields.Count

For Count = 1 To i
On Error Resume Next
pt.PivotFields(Count).Orientation = xlHidden
Next Count

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top