I have created a vba code for creating pivot table which works in the workbook that i created this vba code but when i use this code in another workbook, there is error: subscript out of range.
Sheets.Add ActiveSheet.Name = "Sheet2"
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("WorksheetConnection_Sheet1!$A:$AV"), Version:=6). _
CreatePivotTable TableDestination:="Sheet2!R3C1", TableName:="PivotTable2" _ ,
DefaultVersion:=6
Sheets("Sheet2").Select Cells(3, 1).Select With
ActiveSheet.PivotTables("PivotTable2").CubeFields( _ "[Range].[Purchase Requisition]")
.Orientation = xlRowField .Position = 1 End With
The third paragraph about the workbook connection is where the debugger highlights
Bookmarks