Last active
April 22, 2017 13:42
-
-
Save ateneva/5de9e43878ea0efd065179d92fb2f023 to your computer and use it in GitHub Desktop.
Modify the summary functions for each pivot table in your workbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ModifyDataFieldsSummaryFunction() | |
Dim PT As PivotTable | |
Dim PF As PivotField | |
Dim PI As PivotItem | |
Dim i As Integer | |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
'written by Angelina Teneva, 2014 | |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
For i = 1 To 2 | |
Worksheets(i).Activate | |
Set PT = ActiveSheet.PivotTables(1) | |
Select Case i | |
Case 1 | |
ActiveSheet.name = Format(ActiveSheet.Range("K2"), "dd-mmm") | |
For Each PF In PT.DataFields | |
'must use DataFields Collection if you are going to change the method of consolidation | |
If PF.Position > 4 Then PF.Function = xlCountNums | |
If PF.Position <= 4 Then PF.Function = xlSum | |
If PF.Position <= 4 Then PF.NumberFormat = "0.0" | |
Next PF | |
Case 2 | |
ActiveSheet.name = "weeks" & Format(ActiveSheet.Range("K2"), "dd-mmm") | |
For Each PF In PT.DataFields | |
'must use DataFields Collection if you are going to change the method of consolidation | |
If PF.Position > 3 Then PF.Function = xlCountNums | |
If PF.Position <= 3 Then PF.Function = xlSum | |
If PF.Position <= 3 Then PF.NumberFormat = "0.0" | |
Next PF | |
End Select | |
Next i | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment