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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autosort Script

Status
Not open for further replies.

AtomicWedgie

IS-IT--Management
Jul 10, 2002
227
NL
Hello,

is there maybe a script available to set all fields to autosort that are used in a Pivot Table?

Regards,

Atomic Wedgie
 
Ok,

maybe not the best solution but I came up with this

Sub AutoSortAllPivotFields()

Dim Pivotname As String
Dim ItemCount As Integer
Dim PivotField As String
Dim Count As Integer

Count = 1
Pivotname = ActiveSheet.PivotTables.Item(1).Name
ItemCount = ActiveSheet.PivotTables(Pivotname).PivotFields.Count


Do While Count <= ItemCount

PivotField = ActiveSheet.PivotTables(Pivotname).PivotFields.Item(Count).Value

If PivotField = "Data" Then GoTo Skip

ActiveSheet.PivotTables(Pivotname).PivotFields(PivotField).AutoSort _
xlAscending, PivotField

Skip:

Count = Count + 1

Loop
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top