I made a macro to create pivot table and chart
problem: when I delete the sheet2 and chart1 and run that macro again
there are an error messages in line 9 which is Sheets("Sheet2").Select
question: how to make the macro keep working after deleting the sheet2
and chart1 because I want to make it again after modifying some data
Sub peopleutility()
'
' peopleutility Macro
' Macro recorded 2/24/2005 by wayan sumitra
'
'
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R1085C20").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
Charts.Add
ActiveChart.Location Where:=xlLocationAsNewSheet
Sheets("Sheet2").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Employee(s)")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Actual work"), "Sum of Actual work", xlSum
Sheets("Chart1").Select
End Sub