Setting a Date in VBA?

Nutterhead

New Member
Joined
Apr 25, 2017
Messages
27
I need some Newbie help. I have a code I put together from other post to filter a pivot table based of a cell's data. Now it works fine if I am filtering my "department" filter but I need to filer based off a date. I can't get this to work and it keeps showing an error on Field.CurrentPage = New Cat. I'm assuming this is because the date should not be a string or something like that? Please help?!

Sub Pivot_Update()
'Set the Variables to be used
Dim pt As PivotTable
Dim pt2 As PivotTable
Dim Field As PivotField
Dim NewCat As String

'Update & Refresh Pivot 1 on the sheet
Set pt = Worksheets("1st Time").PivotTables("PivotTable1_1")
Set Field = pt.PivotFields("Date")
NewCat = Worksheets("1st Time").Range("H2").Value

With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With

'Update & Refresh Pivot 2 on the sheet
Set pt2 = Worksheets("1st Time").PivotTables("PivotTable1_2")
Set Field = pt2.PivotFields("Date")
NewCat = Worksheets("1st Time").Range("H2").Value

With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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