Refreshing PivotTable Using Macros

jkuyp

New Member
Joined
Feb 28, 2018
Messages
3
Hey need some help please....

I'm trying to refresh several pivottables across my excel doc with one macro. I want the refresh to be updated data reflecting the most current date (current date being the most recent end of month). I have the code pretty much mapped out and functioning, however it only works when inputting a date manually into the code, but fails when I try to reference another cell.
FvZoM
I want to be able to reference another cell so that I don't have to manually update my macro to reflect the most current date. Sub 'update_piv3t() is where I'm encountering an error. Please help, I apologize any confusion in my explanation.

link to image of code: https://imgur.com/a/FvZoM

Copy&pasted code:

Sub call_on_pivrefresh_troubleshoot()


Call update_piv1t
Call update_piv2t
Call update_piv3t


End Sub


Sub update_piv1t()


Dim pf As PivotField


Set pf = Sheet3.PivotTables("pivot1").PivotFields("[Asof Dt].[Asof Dt].[Asof Dt]")


pf.ClearAllFilters 'clear out any previous filtering


pf.VisibleItemsList = Array( _
"[Asof Dt].[Asof Dt].&[2018-01-31T00:00:00]")

End Sub


Sub update_piv2t()


Dim pf As PivotField


Set pf = Sheet5.PivotTables("pivot2").PivotFields("[Asof Dt].[Asof Dt].[Asof Dt]")


pf.ClearAllFilters 'clear out any previous filtering


pf.VisibleItemsList = Array( _
"[Asof Dt].[Asof Dt].&[2018-01-31T00:00:00]")

End Sub


Sub update_piv3t()


Dim pf As PivotField
Dim test As Variant


Set pf = Sheet7.PivotTables("pivot3").PivotFields("[Asof Dt].[Asof Dt].[Asof Dt]")
test = Sheet1.Range("N4").Value


pf.ClearAllFilters 'clear out any previous filtering


pf.VisibleItemsList = Array( _
"[Asof Dt].[Asof Dt].&[" & (test) & "]")

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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