use dropdown or combobox to change Pivot table selection

JPM

Active Member
Joined
Aug 1, 2002
Messages
407
I am trying to change the fields in a pivot table based upon a selection from a dropdown or combobox. I recorded the following macro as a start, but don't know how to adjust it to make it dynamic with the selection from the box:

Sub OrderType()

Sheets("Pivot").Select
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveSheet.PivotTables("PivotTable5").PivotFields("Channel").Orientation = xlHidden
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Order Type")
.Orientation = xlColumnField
.Position = 1
End With
End Sub

The "Channel" was the old field that needs to be replaced with the new selection (in this case "Order Type").
Any ideas?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Nevermind, I found my own solution by using a dropdown list with the following code. Probably not the sleekest way, but it works:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("$D$53")) Is Nothing Then

Dim ListSelection As String
ListSelection = Worksheets("Dashboard").Range("D53").Value

On Error Resume Next
Sheets("Pivot").Activate
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveSheet.PivotTables("PivotTable5").PivotFields("Brand").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable5").PivotFields("Channel").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable5").PivotFields("Channel Group").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable5").PivotFields("Order Type").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable5").PivotFields("Ship Group").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable5").PivotFields("Ship Method").Orientation = xlHidden

With ActiveSheet.PivotTables("PivotTable5").PivotFields(ListSelection)
.Orientation = xlColumnField
.Position = 1
End With
Sheets("Dashboard").Select
Range("D53").Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,759
Messages
6,132,556
Members
449,735
Latest member
Gary_M

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top