Solved

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

Posted on 2013-01-23
4
326 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
[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:murbro
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:
murbro earned 0 total points
ID: 38831566
I gathered the cell(2,2).value then put it back.
0
 

Author Closing Comment

by:murbro
ID: 38848275
found a simple workaround
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

734 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