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
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