I am trying to use VBA to create a custom sort list for a pivot table based on the order of items on wkst SortLst. My Pivot table is is Sheet2(Company Wide). I am getting subscript out of range error.
Sub PivotTableSortUsingCustomLists3()
Dim rng As Range
Set rng = Worksheets("SortLst").Range("A:A")
Dim PvtTbl As PivotTable
Set PvtTbl = Worksheets("Sheet2").PivotTables("PivotTable1")
Application.AddCustomList rng
PvtTbl.SortUsingCustomLists = True
PvtTbl.PivotFields("Project Name").DataRange.Sort Order1:=xlAscending, Type:=xlSortLabels
End Sub
Sub PivotTableSortUsingCustomLists3()
Dim rng As Range
Set rng = Worksheets("SortLst").Range("A:A")
Dim PvtTbl As PivotTable
Set PvtTbl = Worksheets("Sheet2").PivotTables("PivotTable1")
Application.AddCustomList rng
PvtTbl.SortUsingCustomLists = True
PvtTbl.PivotFields("Project Name").DataRange.Sort Order1:=xlAscending, Type:=xlSortLabels
End Sub