• Change pivot fields en masse

    Author
    Topic
    #461712

    I use many pivot tables and am always forced to change count fields to sum fields one-by-one, and having to format those sum fields in the kind ,0 numeric format. I recorded a macro for one table’s fields that had already been changed from count to sum, but I’m not sure how to generalize such a macro. So how would a macro look that says “for all data fields, change them to sum of and change the format to ,0, for instance? thanks.

    Viewing 1 reply thread
    Author
    Replies
    • #1172492

      Does this do what you want? You must click somewhere in the pivot table before running the macro.

      Code:
      Sub FormatPivotData()
        Dim pt As PivotTable
        Dim pf As PivotField
        Set pt = Selection.PivotTable
        For Each pf In pt.DataFields
      	pf.Function = xlSum
      	pf.NumberFormat = ".0"
        Next pf
      End Sub
    • #1172503

      Seems to work great! Thanks much, a real timesaver.

    Viewing 1 reply thread
    Reply To: Change pivot fields en masse

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: