Run-time error '5' Invalid procedure call or argument when defining Pivot Cache using VBA

前端 未结 2 1953
迷失自我
迷失自我 2021-01-25 05:04

I am finding this issue \"Run-time error \'5\' Invalid procedure call or argument\" when defining the PivotCache on my code. The Excel I am using is 2016 MSO (16.0.4266.1001) 32

相关标签:
2条回答
  • 2021-01-25 05:42

    When creating a PivotCache, MSDN recommends using a String reference to specify the workbook, worksheet and cell range for SourceData, instead of passing a Range object.

    Instead of using PRange (which you've forgotten to Set here), you can use R1C1 notation, like this answer suggests.

    LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    
    ... SourceData:="'US Master Macro'!R1C1:R" & LastRow & "C" & LastCol
    
    0 讨论(0)
  • 2021-01-25 05:49

    Just in case anyone is encountering a similar problem and the above answer does not solve, if you are using Slicers which are connected to various pivots (all of which come from the same data source) then the ChangePivotCache will not work unless you disconnect the pivots from the slicer first. A few days of searching through questions/answers and finally came across the problem!

    0 讨论(0)
提交回复
热议问题