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
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)