+ Reply to Thread
Results 1 to 4 of 4

Unable to set the CurrebtPage property of the PivotField class

  1. #1
    Registered User
    Join Date
    07-18-2016
    Location
    Manchester
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Question Unable to set the CurrebtPage property of the PivotField class

    Hi,

    I have some code to change the filter of a pivot table based off a date in a cell (H2). On a worksheet i have two identical pivots, in pivot1 (CurrentWk) i make a selection of the data i wish to see the data for, i want pivot2 (VsWeek) to show me the data for -7 days of the selected date in pivot1.

    The date in the cell (H2) is -7 days of the selected date in pivot1.

    Code is:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Intersect(Target, Range("H2:H3")) Is Nothing Then Exit Sub

    Dim pt As PivotTable
    Dim Field As PivotField
    Dim NewCat As Date

    Set pt = Worksheets("HistoricalPivot").PivotTables("VsWeek")
    Set Field = pt.PivotFields("[Historical Data].[Date].[Date]")
    NewCat = Worksheets("HistoricalPivot").Range("H2").Value

    With pt
    Field.ClearAllFilters
    Field.CurrentPage = NewCat
    pt.RefreshTable
    End With

    pt.RefreshTable

    End Sub

    The error happens at line highlighted in bold. I've done some looking around and all i can find is that it is something to do with the use of CurrentPage and the fileters i am using but i can't figure out a way around this.

    Any help would be greatly appreciated.

    Thanks,

    Matt

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Unable to set the CurrebtPage property of the PivotField class

    Hi,

    If you don't use an American format for dates, it can be extremely difficult to get CurrentPage to work with a date. It's often simpler to loop through all the items in the date field instead.

    Please Login or Register  to view this content.
    then you would replace your filter lines with:
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    07-18-2016
    Location
    Manchester
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Re: Unable to set the CurrebtPage property of the PivotField class

    I am not using US date format and can't seem to get the above to work.

    Is there no way to get my current code working without the loop?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Unable to set the CurrebtPage property of the PivotField class

    What happens with the code?

    If you format your dates as General - so they appear as plain numbers - then the filter ought to work but it will make your pivot table look strange. I have not checked as to whether a slicer would obviate the date issue with filters.

+ 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. error msg : unable to get the PivotItems property of the PivotField class
    By Kim75 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-12-2015, 03:56 PM
  2. Unable to set orientation property of pivotfield class
    By williams485 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2012, 12:51 PM
  3. runtime 1004 error 'Unable to get the Pivotitems property of the Pivotfield class'
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-01-2012, 10:36 AM
  4. Unable to set the currentpage property of the pivotfield class
    By adoepker in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-09-2011, 06:23 PM
  5. Unable to set the CurrentPage Property of the PivotField Class
    By Murali6688 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2011, 12:16 PM
  6. Unable to set the CurrentPage Property of the PivotField Class
    By SDruley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2011, 01:39 PM
  7. Unable to get the PivotItems Property of the PivotField Class
    By vinay_bagare in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2007, 05:06 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