Order of Pivot Table items

tristanf

New Member
Joined
Jun 1, 2011
Messages
2
I have a list of sales data, including categories and the products within each category. I am trying to specify the order in which the products appear in the pivot table. However, when a product doesn't exist in the data, I get an error. Is there a way to skip over a product if it doesn't exist in the data, ie if Product 2 is not found, then move on to Product 3?

<CODE>
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Category"). _
PivotItems("Product1").Position = 1

ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Category"). _
PivotItems("Product2").Position = 2

ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Category"). _
PivotItems("Product3").Position = 3
etc...
</CODE>


Excel 2007, Windows 7

Thanks for your help!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Untested:

Code:
    Dim Pos As Long
    Pos = 1
    On Error Resume Next
    ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Category"). _
        PivotItems("Product1").Position = Pos
    If Err = 0 Then
        Pos = Pos + 1
    Else
        Err.Clear
    End If
    On Error GoTo 0
    On Error Resume Next
    ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Category"). _
        PivotItems("Product2").Position = Pos
    If Err = 0 Then
        Pos = Pos + 1
    Else
        Err.Clear
    End If
    On Error GoTo 0
    On Error Resume Next
    ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Category"). _
        PivotItems("Product3").Position = Pos
    If Err = 0 Then
        Pos = Pos + 1
    Else
        Err.Clear
    End If
    On Error GoTo 0
    On Error Resume Next
'   Etc
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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