I'm creating pivot tables from each sheet in a workbook. Sometimes I may run across a situation when one sheet doesn't exist. I'd like to be able in that instance to just ignore the missing element and move on to the next element in the array without the script continuing and causing an error. I'm very new to arrays and could use any help I could get. Thanks in advance,
Jimalya
OPTION EXPLICIT
Sub CreateHrsPivot()
Application.ScreenUpdating = False
Dim aSheet As String
Dim myHours As Worksheet
Dim i As Long, lastRow As Long, nCol As Integer
Dim mySheets()
Dim myPath As String
Dim myCharts As Worksheet
Set myHours = Sheets.Add
myHours.Name = "Daily Totals"
'Application.Calculation = xlCalculationManual
mySheets = Array("VOL1", "VOL2", "VOL3", "VOL4")
nCol = 1
For i = 0 To UBound(mySheets)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
mySheets(i) & "!R1C1:R65536C16", Version:=xlPivotTableVersion10). _
CreatePivotTable TableDestination:=Sheets("Daily Totals").Cells(1, nCol), TableName:= _
"PivotHours" & i, DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotHours" & i).PivotFields("Due Date")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotHours" & i).AddDataField ActiveSheet.PivotTables( _
"PivotHours" & i).PivotFields("Daily Total"), "Count of Daily Total", xlCount
With ActiveSheet.PivotTables("PivotHours" & i).PivotFields("Count of Daily Total")
.Caption = mySheets(i)
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotHours" & i)
.ColumnGrand = False
.RowGrand = False
End With
With ActiveSheet.PivotTables("PivotHours" & i).PivotFields("Due Date")
.PivotItems("(blank)").Visible = False
End With
nCol = nCol + 4
Next i
Bookmarks