Solved

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

Posted on 2013-01-23
4
327 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 42

Expert Comment

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

Author Comment

by:Murray Brown
ID: 38813345
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:
Murray Brown earned 0 total points
ID: 38831566
I gathered the cell(2,2).value then put it back.
0
 

Author Closing Comment

by:Murray Brown
ID: 38848275
found a simple workaround
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

624 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