PivotTable Data Type Error

jkuyp

New Member
Joined
Feb 28, 2018
Messages
3
Hey everyone....

I'm looking to create a macro that will update a PivotTable filter to the most current/recent date -- this date will be end of month (so a 01-31 for example, these dates are formatted like -- 2018-01-31T00:00:00). The idea is that the code will reference a cell within my worksheet and apply this cell's value to the PivotTable filter automatically upon the macro's activation. I have constructed a functioning macro that works in being able to complete the above needs, but I am stuck on the ability of the code being able to reference the cell that contains the my desired filter value -- right now I have only been able to manually insert the date into the code, this works, but is not ideal. As you can see from the link I am receiving this error and I don't know how to remedy this problem. The above subs are functioning, but like I said must be manually inputted with data.

Thanks!




Copy & Pasted:

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 String


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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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