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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,823
Messages
6,181,183
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