How to get Multiple items and sum up the same using GetPivotData?

Shafty

New Member
Joined
Mar 20, 2017
Messages
43
VBA Code:
Sub Reconcile()
Dim InputworkBook As Workbook
Dim ReportsToReconcile As Variant
ReportsToReconcile = Array("Report1", "Report2")
Dim ReconcilingReport As Variant
Dim ReportIndex As Integer
ReportIndex = 0
Set InputworkBook = Application.Workbooks.Open(Application.GetOpenFilename, ReadOnly:=True)
With InputworkBook
    Dim PivotsToProcess As Variant
    PivotsToProcess = Array("PivotTable2", "PivotTable3")
    For Each ReconcilingReport In ReportsToReconcile
        Dim DataSheet As Worksheet
        Set DataSheet = .Worksheets(ReportsToReconcile(ReportIndex))
        With DataSheet
            .Parent.Parent.Visible = True
            Dim DataPivot As PivotTable
            Set DataPivot = .PivotTables(PivotsToProcess(ReportIndex))
            With DataPivot
                Dim PivotEntitiesToReconcile As Variant
                PivotEntitiesToReconcile = Array(Array("Sum of STAT FX Book Value", "Sum of STAT FX Net Market Unrealized Valuation Gain/Loss", "Sum of STAT FX Net FX Unrealized Valuation GL"), Array("Sum of STAT FX Market Realized Gain + Sum of STAT FX Market Realized Loss", "Sum of STAT FX FX Realized Gain + Sum of STAT FX FX Realized Loss"))
                Dim SheetEntitiesToReconcile As Variant
                SheetEntitiesToReconcile = Array(Array("SH1", "SH2", "SH3"), Array("SHA", "SHB"))
                Dim PivotEntity As Variant
                Dim EntityIndex As Integer
                EntityIndex = 0
                For Each PivotEntity In PivotEntitiesToReconcile(ReportIndex)
                    If .GetPivotData(PivotEntity) = DataSheet.Cells.Find("Grand Total", after:=DataSheet.Columns(1).Find(SheetEntitiesToReconcile(ReportIndex)(EntityIndex)), searchorder:=xlByColumns).Offset(0, 2).Value Then MsgBox PivotEntity & " reconciles with " & SheetEntitiesToReconcile(ReportIndex)(i) Else MsgBox (EntityInPivot & " Breaks with " & SheetEntitiesToReconcile(ReportIndex)(EntityIndex)) & ". Break Value: " & .GetPivotData(PivotEntity) - DataSheet.Columns(1).Find("Grand Total", after:=DataSheet.Columns(1).Find(SheetEntitiesToReconcile(ReportIndex)(EntityIndex))).Offset(0, 2).Value
                    EntityIndex = EntityIndex + 1
                Next PivotEntity
            End With
        End With
      ReportIndex = ReportIndex + 1
    Next ReconcilingReport
    Call .Close(SaveChanges:=False)
End With
End Sub

The problem is Here:
PivotEntitiesToReconcile = Array(Array("Sum of STAT FX Book Value", "Sum of STAT FX Net Market Unrealized Valuation Gain/Loss", "Sum of STAT FX Net FX Unrealized Valuation GL"), Array("Sum of STAT FX Market Realized Gain + Sum of STAT FX Market Realized Loss", "Sum of STAT FX FX Realized Gain + Sum of STAT FX FX Realized Loss"))

How to GetPivotData for two fields and Sum it up?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Can someone please tell me what have I done wrong?
Good Questions deserve answers... Please Help
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top