VBA change Pivot filter date

JJCA99

Board Regular
Joined
Dec 4, 2014
Messages
50
Hello,
I'm working in a Datavision Pivot table - not sure if that makes a difference.

I'm trying to change my pivot table date based on a cell value but I can't seem to find any code that works.
Keep getting a runtime error 1004
"unable to get the pivotfields property of the pivotTable Class"



Code:
Sub Macro1()
   Dim d As String
    d = "09/30/2017"   'Eventually this will equal cell "F2"

    Worksheets("DV").PivotTables("PivotTable1").PivotFields("date").PivotFilters.Add Type:=xlDateBetween, Value1:=d, Value2:=d
End Sub



Here is snapshot of my data: sorry not sure how to get this pasted in a better format

Code:
[TABLE="width: 513"]
<tbody>[TR]
[TD]POS 1 Tender
[/TD]
[TD](Multiple Items)
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]10/1/2017
[/TD]
[/TR]
[TR]
[TD]POS 1 Category
[/TD]
[TD]Revenues
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]09/30/2017
[/TD]
[/TR]
[TR]
[TD]POS 1 Outlet
[/TD]
[TD]Banquets & Catering
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date
[/TD]
[TD]09/29/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Check Audit Report
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Amount
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level00
[/TD]
[TD]Level01
[/TD]
[TD]Total
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Date
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I think you need to clear the previous filter first.
Test with suitable between dates or use a single criteria method,
 
Upvote 0
I've tried that too but it didn't work. I tried to clear all filters and still the same issue.
-I also added d2 equal to a second date but I'm still getting the runtime error

Is it possible that the Pivotfields name, "date" is listed as something else - how would I check that?
 
Upvote 0
One other thing I noticed, is when I use the filter search box and manually type in a date, I have to search by "DAY" .

There is a drop down list to the right of the search box (year, month, day) and I have to select day for the filter search to work.
-Is that causing my issue, and how would I fix that?
 
Upvote 0
Just record a macro setting the date item.
Field name should come from the header for that data field on the source. Preferably a Table.
 
Upvote 0
One other thing I noticed, is when I use the filter search box and manually type in a date, I have to search by "DAY" .

There is a drop down list to the right of the search box (year, month, day) and I have to select day for the filter search to work.
-Is that causing my issue, and how would I fix that?


umm yeah. Your field is a Date, but your original criteria is Text (String). You should use dates when you have dates...
 
Upvote 0
ok so I tried recording and this is the code that came up - see below.
When I recorded the date as 9/30/2017 the code 6848 where d2 is for date.
-Now I'm getting error, "the item could not be found in the OLAP Cube"

Code:
   Dim d As String
    Dim d2 As String
    d = "09/29/2017"
    d2 = "6848"
    
    
        Range("B4").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("[Date].[Date]"). _
        AddPageItem "[Date].[Date].[Day].&[d2]", True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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