Advertisement

02.20.2008 at 08:12PM PST, ID: 23180108
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Adding/removing calculated fields (formulas) in Excel pivot tables using VBA

Asked by psk1 in Microsoft Excel Spreadsheet Software

Tags: , , , , , , , , , , ,

When a user clicks the drop-down on a group of DataFields in a pivot table, the user can use checkboxes to show all or some of the existing fields.  However, if a user unchecks a box for a field, that field is "gone" and can't be restored by normal user processes.

I've created a button and am using VBA to delete and re-add those fields (see example below).  However, this doesn't work for CalculatedFields.  In fact, all of my attempts have failed miserably, sometimes crashing the pivot table and/or the application.

Does anyone know how to code for the removal/addition of a calculated field to a set of data fields in a pivot table, similarly to the result I achieve with my code sample (below), or know a better solution to my initial issue (above)?

I'm working in Excel 2003.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
resetDataField ActiveSheet.PivotTables("PivotTable1"), "Nbr of Mtgs", "RecordID", "#,###", xlCount
 
resetDataField ActiveSheet.PivotTables("PivotTable1"), "% of Mtgs", "RecordID", "#%", xlCount, xlPercentOfRow
 
 
Private Sub resetDataField(objPivotTable As PivotTable, strFieldCaption As String, strFieldSource As String, strNumberFormat As String, varFunction As Variant, Optional varCalculation As Variant)
    
    Dim i As Integer
    
    With objPivotTable
        For i = 0 To .DataFields.Count - 1
            If UCase(.DataFields.Item(i).Name) = UCase(strFieldCaption) Then
                .DataFields.Item(i).Orientation = xlHidden
            End If
        Next
        .AddDataField .PivotFields(strFieldSource), strFieldCaption, varFunction
        .PivotFields(strFieldCaption).NumberFormat = strNumberFormat
        If Not IsMissing(varCalculation) Then
            .PivotFields(strFieldCaption).Calculation = varCalculation
        End If
    End With
 
End Sub
[+][-]02.21.2008 at 03:19AM PST, ID: 20946604

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.21.2008 at 05:36AM PST, ID: 20947545

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.21.2008 at 05:43AM PST, ID: 20947591

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.21.2008 at 05:55AM PST, ID: 20947673

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.21.2008 at 06:05AM PST, ID: 20947739

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.24.2008 at 08:23PM PST, ID: 20972892

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: excel, pivot table, calculated fields, data fields, datafield, calculatedfield, adddatafield, pivotfields, orientation, hidden, delete, add
Sign Up Now!
Solution Provided By: psk1
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_EXPERT_20070906