Results 1 to 3 of 3

Sort Page Field With VBA

Threaded View

delecto Sort Page Field With VBA 07-13-2009, 02:18 PM
rylo Re: Sort Page Field With VBA 07-13-2009, 09:06 PM
delecto Re: Sort Page Field With VBA 07-14-2009, 08:34 PM
  1. #1
    Registered User
    Join Date
    03-31-2005
    Posts
    11

    Sort Page Field With VBA

    Hi all,

    I have several pivot table templates built, and had to add in additional items to the page field. They are now out of order (they need to be alphabetical). If I was starting from scratch, I would just pull the pagefield down, sort it, and add it back to the top. However, since the entire page is built with formulas and formatting and such, I need to use code.

    SO! Here's what I have so far:

    Sub SortAllFields()
    On Error Resume Next
    Application.ScreenUpdating = False
    
    Dim pt As PivotTable
    Dim ws As Worksheet
    Dim pf As PivotField
    
    For Each ws In ActiveWorkbook.Worksheets
      For Each pt In ws.PivotTables
        pt.ManualUpdate = True
        
        For Each pf In pt.PivotFields
            pf.AutoSort xlAscending, pf.Name
        Next pf
        pt.ManualUpdate = False
      Next pt
    Next ws
    
    Application.ScreenUpdating = True
    
    End Sub
    The problem with this code is that is sorts all pivot fields, and I need it to just sort "Geographies." There is 1 "Geographies" pf per sheet and there are number of sheets in the workbook. I can't figured out how to make the pf specific to "Geographies." Hopefully this makes sense - any help would be appreciated!!

    Thanks,
    Jill
    Last edited by delecto; 07-14-2009 at 08:34 PM. Reason: Question answered

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1