On error not working

Assamita

Board Regular
Joined
Sep 23, 2011
Messages
131
Hi guys,

I have a code to create a Pivot table. A piece of the code orders the columns in a specific order, but it used to fail if there wasn't values of some of the items, so I added the "On error resume next" statement. However, it seems not to be working. This is the code:
Code:
    On Error Resume Next


    With ActiveSheet.PivotTables("Dashboard").PivotFields("Ageing")
        .Orientation = xlColumnField
        .Position = 1
        .PivotItems("Btw 0 and 7 d.").Position = 1
        .PivotItems("Btw 8 and 14 d.").Position = 2
        .PivotItems("Btw 15 and 30 d.").Position = 3
        .PivotItems("Btw 31 and 45 d.").Position = 4
        .PivotItems("Btw 46 and 60 d.").Position = 5
        .PivotItems("Btw 61 and 90 d.").Position = 6
        .PivotItems("More than 90 d.").Position = 7
    End With

Any idea why could this be happening?

Thank you
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
What exactly does "not working" mean? If you're still seeing an error message from that code, then you either have error handling set to break on all errors in your VB Editor settings, or your code is already in an error state when it gets to this section.
 
Upvote 0
Sorry, by "not working" I mean that if the "Btw 15 and 30 d.", for example, is missing, it should skip to the next one and go on with the macro, but instead, it triggers a VBA error message. I don't have a screenshot at the moment, and this macro runs automatically once a day. I'll try to get the next error screenshot and post it here.

I'm thinking that maybe the problem is that if there's not data for the 7 items, therefore the pivot won't have 7 columns at all, and then it fails because I'm trying to give it an order value that it's not possible. I still think it should skip the step and go on, but anyways, I'll try with a loop.

Thank you
 
Upvote 0
You shouldn't see a message unless something else is going on, like the two options I mentioned.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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