ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pivot tables - can change row/col vars but can't get rid of existing vars (https://www.excelbanter.com/excel-programming/390127-pivot-tables-can-change-row-col-vars-but-cant-get-rid-existing-vars.html)

Andreww

Pivot tables - can change row/col vars but can't get rid of existing vars
 
Hi - I am trying to create an xl report based on pivot tables where
the user selects variables from a drop down control and these are
picked up by mode vba code and changes the pivot.

My problem is that while the code essentially works, the previously
chosen vars remain in the pivot!

The code adds vars to the pivot rather than replacing them!

I use the following code that can change the vars in a pivot table.

Sub AllWorkbookPivots()
Dim pt As PivotTable
Dim ws As Worksheet
Dim ptcache As PivotCache
Dim mrow, mcol As Variant


mrow = Sheets("Admin").Range("F3").Value
mcol = Sheets("Admin").Range("F5").Value

Set pt = Sheets("Sheet1").PivotTables(1)

With Sheets("Sheet1").PivotTables(1)
.PivotFields(mrow).Orientation = xlRowField
.PivotFields(mcol).Orientation = xlColumnField
.PivotFields("count").Orientation = xlDataField
End With

End Sub

Any ideas?

Thanks

Andrew



All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com