Hi Guys,
I have a large data source and I trying to create a macro which filters onto the necessary data then copy pastes that data onto separate sheets. From there, I am creating a pivot table off the copy pasted data onto the respective sheets.
From month to month, there will be times where there will be no data available and the VBA I am using errors out (run time 1004) due to not having at least 2 rows of source data. Is there a way to skip this error and for the VBA to go onto the next command? Thanks.
I am receiving an error when I get to the following pivot table command below..
Sheets("Raw Data").Select
Range("B:B,AZ:AZ,AH:AH").Select
Selection.Copy
Sheets("MyTEO").Select
Range("AY1").Select
ActiveSheet.Paste
Set wsTarget = ThisWorkbook.Sheets("MyTEO")
Set rngData = wsTarget.Range("AY:BA").CurrentRegion
Set rngPivotTarget = wsTarget.Cells(1, rngData.Columns.Count + 52)
Set objCache = ThisWorkbook.PivotCaches.Create(xlDatabase, rngData)
Set objTable = objCache.CreatePivotTable(rngPivotTarget)
Set objField = objTable.PivotFields("Customer Personnel Number")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("-5")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("-5.00")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.NumberFormat = " #"
ActiveSheet.PivotTables(1).RowAxisLayout xlTabularRow
ActiveSheet.PivotTables(1).PivotFields("Customer Personnel Number") _
.Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
False, False)
I have a large data source and I trying to create a macro which filters onto the necessary data then copy pastes that data onto separate sheets. From there, I am creating a pivot table off the copy pasted data onto the respective sheets.
From month to month, there will be times where there will be no data available and the VBA I am using errors out (run time 1004) due to not having at least 2 rows of source data. Is there a way to skip this error and for the VBA to go onto the next command? Thanks.
I am receiving an error when I get to the following pivot table command below..
Sheets("Raw Data").Select
Range("B:B,AZ:AZ,AH:AH").Select
Selection.Copy
Sheets("MyTEO").Select
Range("AY1").Select
ActiveSheet.Paste
Set wsTarget = ThisWorkbook.Sheets("MyTEO")
Set rngData = wsTarget.Range("AY:BA").CurrentRegion
Set rngPivotTarget = wsTarget.Cells(1, rngData.Columns.Count + 52)
Set objCache = ThisWorkbook.PivotCaches.Create(xlDatabase, rngData)
Set objTable = objCache.CreatePivotTable(rngPivotTarget)
Set objField = objTable.PivotFields("Customer Personnel Number")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("-5")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("-5.00")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.NumberFormat = " #"
ActiveSheet.PivotTables(1).RowAxisLayout xlTabularRow
ActiveSheet.PivotTables(1).PivotFields("Customer Personnel Number") _
.Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
False, False)