Link to home
Start Free TrialLog in
Avatar of ThomasFoege
ThomasFoege

asked on

Graphs not updating from VBA run code from other sheet

Hello EE!

I have a Sheet1 containing a pivot slicer and a graph
While I in sheet2 have the actual pivot

In Sheet2, under a
Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

Open in new window

It calculates data for a graph based on the pivot data. This I've checked to work.
What does not seem to work though, is this module:

Sub DoGraph(TheSheet As String, TheChart As String, TheSeries As Integer, XValues As Variant, YValues As Variant)
    With Worksheets(TheSheet).ChartObjects(TheChart).Chart
        With .SeriesCollection(TheSeries)
            .XValues = XValues
            .Values = YValues
        End With
    End With
End Sub

Open in new window


I'm then using
DoGraph "Sheet1", "name of graph", "1", XValues, YValues

The slicer, the pivot, the module and the call of the module all worked when it was done in one sheet. However after I moved the pivot to sheet 2, it suddenly does not update the graph.

Is this a restriction in Excel or did my DoGraph break when i started adding Worksheet(TheSheet) instead of the previous Me?
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Are you sure you are passing the right values? Also, are you getting an error, or simply nothing happening? (sample workbook might help)
ASKER CERTIFIED SOLUTION
Avatar of ThomasFoege
ThomasFoege

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm then using
DoGraph "Sheet1", "name of graph", "1", XValues, YValues

Open in new window


Try removing the quotes surrounding "1" in your parameters... the argument type shows it should be an Integer not a string.

Not sure if this is all that is wrong, but it's a start!
Glad you found a fix!
Avatar of ThomasFoege
ThomasFoege

ASKER

Found the problem