I have a workbook with 10 sheets. I tried to automate the creation of pivot table on each sheets through a macro. I recorded the macro for the first sheet called Timetables
Below are part of the scripts:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("WorksheetConnection_Timetables!$A$1:$D$382"), _
Version:=xlPivotTableVersion15).CreatePivotTable TableDestination:= _
"Timetables!R1C5", TableName:="PivotTable1", DefaultVersion:= _
xlPivotTableVersion15
Since each range of data to be used is different on each sheet. I tried to create a variable for that range.
Dim ws as Worksheet
Set ws = Activesheet
Dim wr As Range
Set wr = Range("A1", Range("D1").End(xlDown))
The question is how can I replace the range Timetables!$A$1:$D$382 with the variable on the script?