runtime error - Excel 2010 VBA: Invalid procedure call when adding data field to pivot table -
i want create multiple pivot tables encapsulating complexity functions , procedures (i did manage create pivots vba, 1 module each pivot, meaning lots of repetitive code...)
i managed create procedures , functions create pivot, add filter, , row field. when comes adding data field, invalid procedure call; strange thing error when use variables pass info: looking @ line prodicung error, first line works fine, whereas cannot second line running (the variables contain correct values):
pivotname.adddatafield pivotname.pivotfields("sdid"), "sd id number", xlcount 'works fine pivotname.adddatafield pivotname.pivotfields(fieldname), fielddescription, calcmethod 'produces invalid procedure call error
as running out of ideas, highly appreciated!
thank much,
alexander
the reason error due calcmethod
being declared earlier in code string
.
the .adddatafield
method accepts following parameters:
.adddatafield(field, caption, function)
the parameter function
of xlconsolidationfunction
enum , therefore should declared , assigned below:
dim calcmethod xlconsolidationfunction calcmethod = xlcount
once declared , assigned above, can use within method in following way fieldname
, fielddescription
both strings:
pivotname.adddatafield pivotname.pivotfields(fieldname), fielddescription, calcmethod
Comments
Post a Comment