Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot Table custom sort order

Status
Not open for further replies.

andielangley

Programmer
Feb 11, 2003
17
GB
I have some VBA which successfully creates a pivot table but three of the fields use custom lists for a sort order. How do I get my pivot table to sort the agerange, servrange and salrange fields according to my custom lists as defined in Tools > Options > Custom Lists? Any help would be appreciated. My pivot table code is shown below.
Code:
Cells.Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        ActiveCell.CurrentRegion.Address).CreatePivotTable TableDestination:="", TableName:= _
        "PivotTable1"
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    ActiveSheet.PivotTables("PivotTable1").SmallGrid = False
    ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("Sex", _
        "Contract", "agerange"), ColumnFields:=Array("servrange", "salrange"), _
        PageFields:="Department"
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Payroll No").Orientation = _
        xlDataField
 
As long as the list is stored in your custom lists, if the field entries match that list, just doing an autosort (ascending or descending) should put it in the same order as your list:
syntax as follows:

ActiveSheet.PivotTables("PivotTable4").PivotFields("ROD").AutoSort xlAscending , "ROD"

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top