The code below produces a compile error in the VBA macro builder window. The "red" error line is line 9 (starts with "ActiveWorkbook.PivotCaches...". I'm about 99% sure the problem is with my SourceData value and the range I'm attempting to set this to. Can anyone see anything wrong with this. I'm using the same kind of reference in other places in my VBA code.
Thanks
Thanks
Code:
Sub bldpvt()
Dim iLastRow As Integer
Dim iFirstRow As Integer
Worksheets("AllIndustries").Activate
ActiveCell.SpecialCells(xlLastCell).Select
iLastRow = ActiveCell.Row
iFirstRow = 1
Worksheets("Sheet2").Activate
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
Sheets("AllIndustries").Range("A" & iFirstRow, "N" & iLastRow).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array( _
"Official Customer ", "Industry"), ColumnFields:="Tier"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Account").Orientation = _
xlDataField
Application.CommandBars("PivotTable").Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
Range("A2:G31").Select
Range("G31").Activate
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Range("L7").Select
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array( _
"Official Customer ", "Region"), ColumnFields:="Tier"
ActiveWorkbook.ShowPivotTableFieldList = True
Application.CommandBars("PivotTable").Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub