ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Automatic GETPIVOTDATA formula generation from within VBA? (https://www.excelbanter.com/excel-discussion-misc-queries/192671-automatic-getpivotdata-formula-generation-within-vba.html)

John Brock

Automatic GETPIVOTDATA formula generation from within VBA?
 
If I have a pivot table and I want a formula outside of the table
to refer to one of the table values, I just type "=" and click on
the pivot cell, and Excel automatically generates the appropriate
GETPIVOTDATA(...) formula. This is very convenient (and I know
how to turn the feature off if necessary).

But what if I want to do the same thing from within VBA? Recording
a macro I see something like:

ActiveCell.FormulaR1C1 = "=GETPIVOTDATA(""Data_Field"",R13C26,""Field_1""," "Value_1"",...)"

Conceptually this is easy, but in practice constructing all the
formula strings I'm going to need is going to be a pain. Is there
any way I can ask Excel to construct a GETPIVOTDATA formula
automatically by specifying the cell, the way it works when I do
it by hand?
--
John Brock




All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com