VBA - Subscript Out of Range

Massmann05

New Member
Joined
Mar 22, 2017
Messages
7
Good Afternoon, been racking my brain on this one for awhile and cannot figure it out. I keep getting a subscript out of range on the second line of code listed below. When I run this code on a regular table it works great, but when ran on a pivot table it wont work. Any help would be greatly appreciated. Thank-you!

Code:
Sheets("~Calcs").Select
ActiveSheet.ListObjects("ptCSV1").Range.AutoFilter Field:=8, Criteria1:="<>0"
Call CSV
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
A pivot table is not a ListObject hence the subscript error.

I am not 100% sure, how to get the autofilter to work correctly but the code below errors at the autofilter line only because the filter in incomplete...

Code:
    Dim pivot As PivotTable
    Set pivot = ActiveSheet.PivotTables("ptCSV1")
    pivot.ColumnRange.AutoFilter

I hope this gets you closer...
 
Upvote 0
Thanks for the response, I tried the above with no luck but figured out why. I was trying to apply a filter to a value column in the pt which fo. The below now works, not pretty but works.

Code:
Sheets("~Calcs").Select
ActiveSheet.PivotTables("ptCSV1").PivotFields("Cost").PivotFilters.Add Type:= _
xlValueDoesNotEqual, DataField:=ActiveSheet.PivotTables("ptCSV1").PivotFields _
("Sum of Qty"), Value1:=0
 
Upvote 0
Thanks for the feedback. I am glad you have it working, pretty or not!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
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