VBA to Refresh Pivots

happyhungarian

Active Member
Joined
Jul 19, 2011
Messages
254
Office Version
  1. 365
Platform
  1. Windows
Hi, I have the following code that takes values selected via a list on a worksheet named "Trended P&L" that takes the value that's placed in cell D3 and uses that value to refresh a pivot table located on a worksheet named "Travel".

Private Sub Worksheet_Change(ByVal Target As Range)
Dim FTW As String
If Not Intersect(Target, Range("D3")) Is Nothing Then
FTW = Worksheets("Trended P&L").Range("D3").Value
Worksheets("Travel").Range("B2").Value = FTW
End If
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String

'Here you amend to suit your data
Set pt = Worksheets("Travel").PivotTables("PivotTable1")
Set Field = pt.PivotFields("VP")
NewCat = Worksheets("Travel").Range("B2").Value

'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub



The issue I'm having is i'd like to have multiple cells used to refresh the pivot table. For example, rather have it just reference D3 on the Trended P&L tab, I would like it to reference D3:D5 and change the values on pivot filters in ranges B2:B4. However, when I try various methods it always errors out when trying to change the second filter.

Thanks for the help!!

Jesse
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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