gmbristow91
New Member
- Joined
- Feb 2, 2016
- Messages
- 41
Hi, I would like to be able to edit pivot fields with whatever I choose from a dropdown list. I have already been able to do this with the report filter (In my case the client name). I would like to be able to choose what shows up in the columns of the pivot table though. Thank you all in advance. My code is as follows:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String
strField = "Name"
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Address = Range("SelectClient").Address Then
' For Each ws In ThisWorkbook.Worksheets
Set ws = Me
For Each pt In ws.PivotTables
With pt.PageFields(strField)
For Each pi In .PivotItems
If pi.Value = Target.Value Then
.CurrentPage = Target.Value
Exit For
Else
.CurrentPage = "(All)"
End If
Next pi
End With
Next pt
' Next ws
End If
For Each pt In Me.PivotTables
pt.RefreshTable
Next pt
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub