Pivot GetPivotData In VBA

ajmplanner

New Member
Joined
Jan 24, 2015
Messages
4
I have 2 worksheets
In Sheets ("Closed Trans") I have a Pivot Table: Col 1 is named CL Date and Col 2 is named Net Realized Gain

In Sheets("Summary") I have 2 columns: Col A and Col B. Col A contains a date
I want to extract the Net Realized gain from the pivot table in Sheets("Closed Trans") based on the date in COL A and insert it into Col B in Sheets("Summary")
There are nsummary number of dates in COl A

My code is

For i = 3 To nsummary
lkup = Format(Cells(i, 1).Value, "mm/dd/yy" )
cells(i,2).value=GETPIVOTDATA("Net Realized Profit",'Closed Trans'!$A$1,"Cl Date","), lkup)

Next i

The compiler will not accept my formula for rg. I tried including WorksheetFunction.GetPivotData, and also a specific date for lkup with same result for both

However, if I type =GETPIVOTDATA("Net Realized Profit",'Closed Trans'!$A$1,"Cl Date","), "03/15/21") directly into a cell in Sheets("Summary"), I get a correct result
What am I missing here? Thanks in advance for any replies.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I have 2 worksheets
In Sheets ("Closed Trans") I have a Pivot Table: Col 1 is named CL Date and Col 2 is named Net Realized Gain

In Sheets("Summary") I have 2 columns: Col A and Col B. Col A contains a date
I want to extract the Net Realized gain from the pivot table in Sheets("Closed Trans") based on the date in COL A and insert it into Col B in Sheets("Summary")
There are nsummary number of dates in COl A

My code is

For i = 3 To nsummary
lkup = Format(Cells(i, 1).Value, "mm/dd/yy" )
cells(i,2).value=GETPIVOTDATA("Net Realized Profit",'Closed Trans'!$A$1,"Cl Date","), lkup)

Next i

The compiler will not accept my formula for rg. I tried including WorksheetFunction.GetPivotData, and also a specific date for lkup with same result for both

However, if I type =GETPIVOTDATA("Net Realized Profit",'Closed Trans'!$A$1,"Cl Date","), "03/15/21") directly into a cell in Sheets("Summary"), I get a correct result
What am I missing here? Thanks in advance for any replies.
Shouldhave said formula cor cells(i,2).value
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top