'SECTION TWO - create new worksheets for each individual cost centre based on variables
'Create sheet 1
Set Newsheet1 = Worksheets.Add
Newsheet1.Name = outputvar1
Range("A1").FormulaR1C1 = "This sheet will hold the pivot for:"
Range("D1").FormulaR1C1 = outputvar1
^^ This works fine
'Creates the pivot table on sheet
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Control!$A:$X").CreatePivotTable TableDestination:= _
"'[Overheads.Engine.xls]100241'!R5C1", TableName:="PivotTable1",
DefaultVersion:=xlPivotTableVersion10
^^ so does this (where the sheet is referenced as a fixed name (100241)
'Creates the pivot table on sheet
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Control!$A:$X").CreatePivotTable TableDestination:= _
"'[Overheads.Engine.xls]outputvar1'!R5C1", TableName:="PivotTable1",
DefaultVersion:=xlPivotTableVersion10
BUT it is really important that I am able to reference the sheet as a variable as i am dynamically creating up to 10 sheets which could have any different cost centre number (which means i cant hard code the sheet number as above)
Since i create the pivots on each sheet as i go, is there any way to replace referncing the sheet by it name by using some other type such as "active sheet??"
Bookmarks