Does anyone have a definitive code that works for UK Regional Date setting for filtering a pivot table between a date range where the dates are based on two cell values outside the pivot table (of course) ?
I had the code working fine until I spotted that it wasn't working all the time and finally discovered that it was due to a US Date format issue and whilst I found lots of discussion on the subject in various places... regarding regional settings... no solution seemed apparent ?
The table is updated daily so initially my code was based on simply setting the new day pivot item to visible and the new day minus 7 to invisible - thus filtering for the past week (which is my aim).
The 16/05/2013 was set to invisible but debugging the code - the 09/05/2013 to invisible never executed - see below.
[pre]
[/pre]
Any assistance gratefully received...
Regards
Jabba
I had the code working fine until I spotted that it wasn't working all the time and finally discovered that it was due to a US Date format issue and whilst I found lots of discussion on the subject in various places... regarding regional settings... no solution seemed apparent ?
The table is updated daily so initially my code was based on simply setting the new day pivot item to visible and the new day minus 7 to invisible - thus filtering for the past week (which is my aim).
The 16/05/2013 was set to invisible but debugging the code - the 09/05/2013 to invisible never executed - see below.
[pre]
Code:
Private Sub ApplyDateWkFilter()
Dim pvtTable As PivotTable
Dim pvtField As PivotField
Dim pvtItem As PivotItem
Dim filterDate1 As Date, filterDate2 As Date
Application.ScreenUpdating = False
filterDate1 = CDate(Range("EvtDte"))
filterDate2 = CDate(Range("EvtDte_7"))
On Error Resume Next
Set pvtTable = Worksheets("DailyWatchCalc").PivotTables("PvtTblWkSentOutMWH")
Set pvtField = pvtTable.PivotFields("Event Date")
pvtTable.RefreshTable
For Each pvtItem In pvtField.PivotItems
Select Case CDate(pvtItem.Value)
Case filterDate1
pvtItem.Visible = True
Case filterDate2
pvtItem.Visible = False
Case Else
End Select
Next pvtItem
Any assistance gratefully received...
Regards
Jabba