+ Reply to Thread
Results 1 to 4 of 4

Retrieve min & max values from pivot filter/field

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Retrieve min & max values from pivot filter/field

    Hi all,

    I have a pivot that I need to refresh every few days. Since the data keeps changing, I want the Macro to find the earliest and latest fiscal year in the pivotfield "Fiscal Year" automatically. How can I achieve that with code?

    FY.PNG

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,926

    Re: Retrieve min & max values from pivot filter/field

    Posts: 371 and you posted a pic?
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Retrieve min & max values from pivot filter/field

    I was in a rush and thought it was straight forward, apparently it is not

    Here's what I've got so far:

        Dim t As Long
        
        Dim v1 As String
        Dim v2 As String
        
        Dim TSS As String
        Dim LSS As String
        
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        
        Workbooks.Open FileName:="S:\COMMON-HK2\HK-APAC-MAP\Range Plan\Buy Recap - RCPT DATA.xlsb", UpdateLinks:=False, ReadOnly:=True
        
        Sheet22.PivotTables("RCPT TY").PivotCache.Refresh
        
        Workbooks("Buy Recap - RCPT DATA.xlsb").Close SaveChanges:=False
        
        t = Sheet22.PivotTables("RCPT TY").PivotFields("Fiscal Year").PivotItems.Count - 1
        
        Sheet22.PivotTables("RCPT TY").PivotFields("Fiscal Year").PivotItems("(blank)").Position = t + 1
        
        v1 = Sheet22.PivotTables("RCPT TY").PivotFields("Fiscal Year").PivotItems(1).Name
        v2 = Sheet22.PivotTables("RCPT TY").PivotFields("Fiscal Year").PivotItems(t).Name
        
        TSS = "SS" & Evaluate("If(SeasonName=""SPRING"",Min(Right(""" & v1 & """,2), Right(""" & v2 & """,2)),Max(Right(""" & v1 & """,2), Right(""" & v2 & """,2)))")
        LSS = "SS" & Right(TSS, 2) - 1
        
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
    My assumption currently is that there's a maximum of 2 fiscal years in the pivot field, though, this might change in the future, so I need to adjust the code to get the max and min for all values except "(blank)"...

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2502
    Posts
    13,700

    Re: Retrieve min & max values from pivot filter/field

    Does it have to be VBA?

    A file upload gives us real context to apply proposals to.
    Dave

+ 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. Replies: 0
    Last Post: 07-14-2016, 03:51 PM
  2. Retrieve data from Pivot under Filter
    By zeta274 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-09-2016, 03:39 PM
  3. [SOLVED] A pivot table field calculated using other field values as fields?
    By chrisf78 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 05-07-2015, 03:08 AM
  4. Replies: 0
    Last Post: 03-20-2015, 11:39 AM
  5. Pivot Table field show values as % of another value field
    By amotto11 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-27-2015, 04:31 PM
  6. [SOLVED] How to set a 'Date Filter' on a field in the 'Report Filter' section of a Pivot Table?
    By Rhino_dance in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 03-28-2013, 11:01 AM
  7. Replies: 0
    Last Post: 07-21-2010, 01:43 PM

Tags for this Thread

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