+ Reply to Thread
Results 1 to 1 of 1

VBA code to run Multi value fields selection in Pivot table

  1. #1
    Registered User
    Join Date
    04-16-2014
    Location
    Hochiminh
    MS-Off Ver
    Excel 2010
    Posts
    1

    VBA code to run Multi value fields selection in Pivot table

    Hello,

    I am new comer to Excel Forum family. I have gone through and get the VBA code from Anne to change value field of pivot table (Pivot table contain 6 value fields for Sum of)
    The code allow user to select one month only. I modified the code so that i can select more than 2 months but could not.
    Can anyone review attached file and advise?

    [Private Sub CommandButton1_Click()
    On Error Resume Next
    Dim pf As PivotField
    Dim month As String
    Dim curm As String
    For Each pf In Sheet3.PivotTables("PivotTable1").DataFields
    curm = pf.Name
    Next pf
    month = Sheet2.Range("B10")
    If month = Right(curm, 6) Then Exit Sub
    Application.ScreenUpdating = False
    Sheet3.PivotTables("PivotTable1").AddFields RowFields:=Array("Supplier", _
    "RM Name")
    Sheet3.PivotTables("PivotTable1").PivotFields(curm). _
    Orientation = xlHidden
    With Sheet3.PivotTables("PivotTable1").PivotFields(month)
    .Orientation = xlDataField
    .Caption = "Sum of " & month
    .Function = xlSum
    .NumberFormat = "[$$-409]#'##0.00"
    End With
    Sheet3.PivotTables("PivotTable1").PivotFields("Data").PivotItems( _
    "Sum of " & month).Position = 1
    Application.ScreenUpdating = True
    Application.Goto Sheet3.Range("A3")

    End Sub
    ][/QUOTE]


    Thanks,
    Nhuttrung
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Code for Removing All Value Fields in a Pivot Table
    By lufcluke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-23-2015, 01:09 PM
  2. Replies: 9
    Last Post: 02-26-2014, 04:17 PM
  3. [SOLVED] Adding Calculated Fields to a Pivot Table Code
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2012, 06:36 PM
  4. How to Disable automatic fields in pivot table like total and count on fields
    By anushka in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2009, 07:53 AM
  5. How to pull values from the pivot table fields, through the code/.
    By seven_snow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2006, 07:50 AM

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