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
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
Posts: 371 and you posted a pic?
Ben Van Johnson
I was in a rush and thought it was straight forward, apparently it is not
Here's what I've got so far:
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)"...![]()
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
![]()
Does it have to be VBA?
A file upload gives us real context to apply proposals to.
Dave
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks