Solved

VB.net/VBA Pivot table refreshes in different form/filter

Posted on 2013-01-23
4
321 Views
Last Modified: 2013-02-03
Hi

 In my Excel Add-in I use the following code in refreshing a pivot table after
changes to the data behind it are made. The problem is that the pivot table
doesn't go back to the state that it was in before. Is there a way to stop this?


Sub ChangePivotSource()
        Try
            Dim oPT As Excel.PivotTable
            Dim oPC As Excel.PivotCache

            Globals.ThisAddIn.Application.Sheets("Pivot").activate()
            oPT = Globals.ThisAddIn.Application.ActiveSheet.PivotTables(1)

            oPC = oPT.PivotCache
            oPC.SourceData = "Data!" & Globals.ThisAddIn.Application.ConvertFormula("$A$1:$F$90", Excel.XlReferenceStyle.xlA1, Excel.XlReferenceStyle.xlR1C1)


            oPT.RefreshTable()

            If Not oPT Is Nothing Then oPT = Nothing

            If Not oPC Is Nothing Then oPC = Nothing

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
0
Comment
Question by:murbro
  • 3
4 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
what do u mean by go back to the state that it was in before?
0
 

Author Comment

by:murbro
Comment Utility
When I open the saved Excel sheet the pivot looks like the first image.
I then go to the second image, make my changes, and hit the button that
refreshes the pivot table with the data that I have changed.
After the refresh the pivot goes back to the state it is in in the first image,
when I need it to go back to the second image

12
0
 

Accepted Solution

by:
murbro earned 0 total points
Comment Utility
I gathered the cell(2,2).value then put it back.
0
 

Author Closing Comment

by:murbro
Comment Utility
found a simple workaround
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now