VBA Code for PivotTable

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I have been unable figure out VBA code to just extract the number/value, rather than filling a cell with the figure and then using the cell value to fill a variable.

Code:
Range("B22").Formula = "=GETPIVOTDATA(""Sum of Hours"",Pivot!$A$1,""Pay Period"",DATE(year($A$2),month($A$2),day($A$2)),""Office"",""Eastern"")"
number1 = Range("B22").value

Help, please?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
The PivotTable object has a GetPivotData method... ;)
 
Upvote 0
So, I tried...

Code:
number1 = PivotTable2.GetPivotData("Sum of Reg Hours", "Pay Period", Range("A2"), "Office", Range("A9"))

...and no dice, "Object Required".
Range("A2") is a Date field.
Range("A9") = "Eastern"
 
Upvote 0
Where/how did you declare and initialise your PivotTable2 variable?
 
Upvote 0
And how did you assign a pivot table to it?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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