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

前端 未结 2 1958
迷失自我
迷失自我 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
    

提交回复
热议问题