Consulting

Results 1 to 3 of 3

Thread: Change Pivot Table Date Filter to Cell Reference

  1. #1
    VBAX Newbie
    Joined
    Feb 2021
    Location
    Perth
    Posts
    1
    Location

    Cool Change Pivot Table Date Filter to Cell Reference

    Hello

    I need to do something really simple where I have many many pivot table in my report that required to updated every day
    This involved changing the date filter

    I have seen many posts on this however I always have issue with the identifying the correct PivotFields.
    The data is obtained from Cube database and seems to have an array filter date.

    Below is an example code where i just do the macro recording...


    End goal is to change the date filter from [20-FEB-21] to a cell refence at H2

    Thank youu



    Sub Change_Date()
    '
    ' Change_Date Macro
    '


    '
    Sheets("Truck Usage").Select
    ActiveSheet.PivotTables("Pivot_TruckHourly").PivotFields("[TIME].[TIME].[Year]" _
    ).VisibleItemsList = Array("")
    ActiveSheet.PivotTables("Pivot_TruckHourly").PivotFields( _
    "[TIME].[TIME].[Month]").VisibleItemsList = Array("")
    ActiveSheet.PivotTables("Pivot_TruckHourly").PivotFields("[TIME].[TIME].[Day]") _
    .VisibleItemsList = Array("[TIME].[TIME].[Day].&[20-FEB-21]")
    End Sub

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to the forum.

    please use code tags when posting your code. (see my forum signature.)

    dose this work for you?
    PHP Code:
    ActiveSheet.PivotTables("Pivot_TruckHourly").PivotFields("[TIME].[TIME].[Day]"_
    .VisibleItemsList = Array("[TIME].[TIME].[Day].&[" Range("H2").Value "]"
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    using dates (especially non MDY format) may cause pain in VBA.

    if above does not work, you may try below (or maybe stg else)
    PHP Code:
    ActiveSheet.PivotTables("Pivot_TruckHourly").PivotFields("[TIME].[TIME].[Day]"_
    .VisibleItemsList = Array("[TIME].[TIME].[Day].&[" Format(Range("H2").Value"DD-MMM-YY") & "]"
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •