Assistance with VBA Code Error

jgome21

New Member
Joined
Nov 26, 2017
Messages
13
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)
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top