Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Philadelphia, Pennsylvania
    Posts
    676
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Philadelphia, Pennsylvania
    Posts
    676
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seems to work great! Thanks much, a real timesaver.

Posting Permissions

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