theteacher9999
New Member
- Joined
- Jun 8, 2020
- Messages
- 12
- Office Version
- 365
- 2010
- Platform
- Windows
I'm trying to solve a problem, so far without success. I have a pivot table and , with VBA code, I would like the values in the 'Country' field to be in the exact order I specified:
(blank), Czech Republic, Finland, Denmark, Norway, Spain, Greece, Brazil, Argentina
This is what I have:
I know Norway isn't in my table, but if it does show up, it should be in the right place after running the code.
I was trying to achieve my goal using the code below but with no luck.
BTW, when I run it and then I sort the column manually (A to Z), I get the below:
It seems to be fine except "(blank)" which is not at the beginning. I am confused. Do you have an idea how to solve it?
(blank), Czech Republic, Finland, Denmark, Norway, Spain, Greece, Brazil, Argentina
This is what I have:
I know Norway isn't in my table, but if it does show up, it should be in the right place after running the code.
I was trying to achieve my goal using the code below but with no luck.
VBA Code:
Dim PvtTbl As PivotTable
Set PvtTbl = Worksheets("Sheet4").PivotTables("PivotTable2")
Application.AddCustomList Array("(blank)", "Czech Republic", "Finland", "Denmark", "Spain", "Greece", "Brazil", "Argentina")
PvtTbl.SortUsingCustomLists = True
PvtTbl.PivotFields("Country").DataRange.Sort Order1:=xlAscending, Type:=xlSortLabels
BTW, when I run it and then I sort the column manually (A to Z), I get the below:
It seems to be fine except "(blank)" which is not at the beginning. I am confused. Do you have an idea how to solve it?