Update date range in Pivot table based on two cell references UK dates

MuppetReaper

New Member
Joined
Jun 14, 2013
Messages
30
Hi

I am trying to write some code to update a pivot based on dates in two other cells, all my dates are UK formatted, but I can not get it to work - any ideas please, it's driving me nuts -
the two dates are DateFrom = 25/11/2014 and SatDate = 03/10/2015

Code:
Sub MondayUpdates()
    
    DateFrom = Range("Dates!C16")
    SatDate = Range("Dates!C7")
    Sheets("Exceptions").Select
        ActiveSheet.PivotTables("PivotTable1").PivotFields("scan_date_all").PivotFilters. _
       Add Type:=xlDateBetween, Value1:=DateFrom, Value2:=SatDate
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
sorry to bump, but does anyone have any ideas? I'm sure the issue is with the fact that it's UK dates as I have tried recording a macro just to select a few dates from the pivot table, butn then when I try to rerun that, even that doesn't work!

Code:
Sub Macro3()
    Sheets("Exceptions").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("scan_date_all"). _
        CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("scan_date_all")
        .PivotItems("25/11/2014").Visible = True
        .PivotItems("18/12/2014").Visible = True
        .PivotItems("22/12/2014").Visible = True
    End With
End Sub
 
Upvote 0
Hi all
after much playing oround I've actually found a solution and thought I'd post it here, in case it was useful for anyone else, so sorry for replying to my own thread so many times!
First I made sure that the date format in the pivot is set as date (UK) and the 3rd option down - 14/03/2001
the macro still doesn't work if you don't do that first
Then I just had to make the date in the macro have quotes around it and hey presto!!
Code:
    Sheets("Exceptions").Select
    For i = 0 To 10
        ScanDate = Range("Dates!C9") - i
        On Error Resume Next
        ScanDate = "" & ScanDate & ""
        ActiveSheet.PivotTables("PivotTable1").PivotFields("scan_date_all"). _
            CurrentPage = "(All)"
        With ActiveSheet.PivotTables("PivotTable1").PivotFields("scan_date_all")
            .PivotItems(ScanDate).Visible = True
        End With
    Next i
    Err.Clear
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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