+ Reply to Thread
Results 1 to 7 of 7

PivotField Date Filter working

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    PivotField Date Filter working

    The first loop works fine but the second date filter won't update. Any ideas would be great :

        Dim Pt as PivotTable
        Dim Pf as PivotField
        Dim Pi as PivotItem    
    
        Set Pt = Worksheets("Sheet1").PivotTables("Pivot1")
        Set Pf = Pt.PivotFields("Sales")
    
            For Each Pi In Pf.PivotItems
                If Pi.Value = "0" Then
                    Pi.Visible = False
                Else
                    Pi.Visible = True
                End If
                    On Error Resume Next
            Next Pi
                
        Today = Date
        Set Pf = Pt.PivotFields("Dates")
            Pf.PivotFilters.ClearAllFilters
            Pf.PivotFilters.Add Type:=xlBefore, Value1:=Today
    Thanks !

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: PivotField Date Filter working

    You may use
            Pf.ClearAllFilters
            Pf.PivotFilters.Add Type:=xlBefore, Value1:=CLng(Today)

  3. #3
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: PivotField Date Filter working

    That doesn't work either. I muse have something elsewhere in my code that's not working. Do you think clearing the cache would change anything ?

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: PivotField Date Filter working

    Is your field really a date type? Can you manually use the date filters on it?

  5. #5
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: PivotField Date Filter working

    Yes I can manually use the date filters on it. If I use the Macro Recorder, I get the following code :

    ActiveSheet.PivotTables("Pivot1").PivotFields("Dates"). _
    PivotFilters.Add Type:=xlBefore, Value1:="12/17/2013"

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: PivotField Date Filter working

    May you provide a workbook? The solution I suggested does work with Excel 2010 when I test it.

  7. #7
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: PivotField Date Filter working

    I'd like to but can't. Thanks again for your help Izandol !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA & PivotField Code
    By rrhutch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2021, 11:23 PM
  2. Date Filter is not working, beside filtering data also needs some help.
    By sanc.jobs2012 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2012, 05:51 AM
  3. Date Filter working In One Computer but Not Another
    By coolchick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2010, 11:26 PM
  4. How to get the PivotField i've clicked on?
    By opc10 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2007, 05:38 PM
  5. PivotField select all
    By CinqueTerra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2005, 09:00 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1