Extract Data (double click) from Pivot Table thru VBA

harishs

Board Regular
Joined
Jul 3, 2016
Messages
50
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Experts,

Found this code in Google, modified as per my requirement, however, I am unable to extract data in the new sheet.

Need your help in updating the code or help me with code which satisfies the requirement.

I need to run this code to extract data from another workbook (currently, we manually double click to get data and move data to a new sheet).

Code:
Sub CopyPivotItemDataRange()
Dim wb1 As Excel.Workbook
Set wb1 = Workbooks.Open("C:\Users\Desktop\Sell 2018.xlsm", Password:="test", ReadOnly:=True)
Application.Run ("'Sell 2018.xlsm'!CODE_RUN")
Dim PvtTbl As PivotTable
Dim PvtFld As PivotField
Set PvtTbl = wb1.Sheets("Summary").PivotTables("PivotTable3")
Set PvtFld = PvtTbl.PivotFields("Month")
With PvtFld
    .PivotItems("Aug 18 Total").ShowDetail = True 'Show pivot item
    .PivotItems("Aug 18 Total").DataRange.EntireRow.Copy Destination:=Workbooks("extract.xlsm").Sheets("Sheet2").Range("A1")
End With
End Sub

My requirement is to extract data of subtotal of a month specified in the code.

Regards,
Harish S
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,979
Messages
6,122,560
Members
449,089
Latest member
Motoracer88

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