getPivotData

K

KyWilde

I am trying to use a variable in the GetPivotData function and I keep getting
#REF error. Here is my syntax:
Cells(lRow, 5).Select
ActiveCell.FormulaR1C1 = _
"=GETPIVOTDATA(""Sum of
xfers"",Pivot_table!R3C1,""day"",DATE(2005,3,29)"

When I try:
Cells(lRow, 5).Select
ActiveCell.FormulaR1C1 = _
"=GETPIVOTDATA(""Sum of xfers"",Pivot_table!R3C1,""day"",temp3)"

using temp3, a variable holding a date, it gives me a #REF error. Can I not
use variables here? What can I do to make this dynamic?

Thanks.
 
P

Patrick Molloy

you're hard-coding the word temp3 instead of using it as a variable

const FORMULA as String = _
"=GETPIVOTDATA(""Sum of xfers"",Pivot_table!R3C1,""day"",TEMP3)"
dim sFormula as String
sFormula = Replace( FORMULA,"TEMP3",temp3)
ActiveCell.FormulaR1C1 = sFormula


you could simply concatenate it, but the code above is real easy to see and
understand and debug.

ActiveCell.FormulaR1C1 = _
"=GETPIVOTDATA(""Sum of xfers"",Pivot_table!R3C1,""day""," & temp3 & ")"
 
K

KyWilde

Thanks Patrick... unfortunately when I use the recommended code I get the
same #REF error. This is really confusing me. Any more suggestions?
Thanks!
 
P

Patrick Molloy

the #REF suggests that you're trying to read /use a range that doesn't
exist.
 
D

Debra Dalgleish

Try converting the date to a long integer:

"=GETPIVOTDATA(""Sum of xfers"",Pivot_table!R3C1,""day""," &
CLng(temp3) & ")"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top