I have a pivot table set up(see image to get a better idea). I am trying to extract data from the pivot table based on the country. You can see that the row country gives access to the row region, and the row region gives access to row product. I want to copy the data under the constraint of: France
to get both regions, all products, and the sum of price and move it to sheet2.
Here is my idea how I could go about it, but the select method is not supported in the current property/method. How might I go about selecting all of the data under france?
Sheets("MY Pivot").PivotTables("MY_Pivot").PivotFields("Country").PivotItems("France" _
).ShowDetail = True 'Show pivot item
Sheets("MY Pivot").PivotTables("MY_Pivot").PivotFields("Country").PivotItems("France" _
).Select 'Select pivot item to copy
Selection.Copy 'Copy the pivot items
Sheets("Sheet2").Range("A1").Select 'Select sheet cell for paste
Sheets("Sheet2").Paste 'Paste the selected France results
You can copy the .PivotItems("France").DataRange.EntireRow
to "Sheet2", without the need to use Select
.
Code
Option Explicit
Sub CopyPivotItemDataRange()
Dim PvtTbl As PivotTable
Dim PvtFld As PivotField
' set the Pivot Table object
Set PvtTbl = Sheets("MY Pivot").PivotTables("MY_Pivot")
' set the Pivot Field object
Set PvtFld = PvtTbl.PivotFields("Country")
With PvtFld
.PivotItems("France").ShowDetail = True 'Show pivot item
' copy >> paste the entire Range data under "France" to "Sheet2"
.PivotItems("France").DataRange.EntireRow.Copy Destination:=Sheets("Sheet2").Range("A1")
End With
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.