Create Pivot in present sheet from data located in another closed workbook

Shiro26

Board Regular
Joined
Oct 2, 2015
Messages
82
Hi,

I have an issue regarding the code i wrote.
I am trying to create in a specific cell of a specific sheet of the workbook from which the module is located a pivot table for which the data comes from another workbook which is closed.

But I have an error when it come to the last three lines.

Has anybody seen the same issue? if yes, could i have some hints on how to tackle it please?

Thank you for your help

Code:
Dim RECwbk as workbook
dim INVwbk As Workbook
Dim RECINVPIVOTsht as worksheet
dim INVDATAsht As Worksheet
Dim USERID As String
Dim StartPoint as range
dim INVDataRange As Range
Dim INVDatasrc as srting
dim PivotDest as string
dim RECINVPivot As String
Dim pvtCache As PivotCache
Dim pvt As PivotTable

USERID = "30"              
Path = "P:\Documents\AUTO_TEST\"
'Set Variables Equal to Data Sheet and Pivot Sheet
INVwbkFN = USERID& "_INV.xlsm"
Set INVwbk = Workbooks.Open(FileName:=Path & INVwbkFN, UpdateLinks:=0)
Set INVDATAsht = INVwbk.Worksheets("INVSOURCEDATA")

'destination for the pivot
Set RECINVPIVOTsht = ThisWorkbook.Worksheets("INVPivot")
    
RECINVPivot = "PivotTable1"
    
'Dynamically Retrieve Range Address of INV Data
  Set INVStartPoint = INVDATAsht.Range("A1")
  Set INVDataRange = INVDATAsht.Range(StartPointINVStartPoint.SpecialCells(xlLastCell))
    
'Data range you want to pivot
  INVDatasrc = INVDATAsht.Name & "!" & INVDataRange.Address(ReferenceStyle:=xlR1C1)

'Create Pivot Cache from Source Data
    Set pvtCache = ActiveWorkbook.PivotCaches.Create( _
    SourceType:=xlDatabase, _
    SourceData:=INVDatasrc)

'Pivot starting point
  PivotDest = RECINVPIVOTsht.Name & "!" & RECINVPIVOTsht.Range("B10").Address(ReferenceStyle:=xlR1C1)

'Create Pivot table from Pivot Cache
  Set pvt = pvtCache.CreatePivotTable(TableDestination:=PivotDest)
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,029
Messages
6,122,760
Members
449,095
Latest member
m_smith_solihull

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