Hello All,
I am having some difficulty with a slight spin on a familiar problem.
I am attempting to have my macro update the selected items in a pivot field. I want the macro to only select yesterdays date from the pivot field list.
At the moment, when i attempt to set the date as yesterdays, i get a "Type Mismatch" error from Excel.
Any ideas anyone, as I am stumped. Thanks sooo much.
Regards
Code below:
Sub Macro2()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = Sheets("APAC").PivotTables(1)
Set pf = pt.PivotFields("Create Day")
Set pi = DateAdd("dd", -1, "mm/dd/yyyy")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
With pf
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I am having some difficulty with a slight spin on a familiar problem.
I am attempting to have my macro update the selected items in a pivot field. I want the macro to only select yesterdays date from the pivot field list.
At the moment, when i attempt to set the date as yesterdays, i get a "Type Mismatch" error from Excel.
Any ideas anyone, as I am stumped. Thanks sooo much.
Regards
Code below:
Sub Macro2()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = Sheets("APAC").PivotTables(1)
Set pf = pt.PivotFields("Create Day")
Set pi = DateAdd("dd", -1, "mm/dd/yyyy")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
With pf
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub