Link to home
Start Free TrialLog in
Avatar of sjgrey
sjgreyFlag for Australia

asked on

Excel chart data label not updating

I have a chart driven by data placed in a sheet using some VBA code.  The chart includes a data label that picks up the content of a cell where the label is created by the same VBA code.

The lines on the chart update when the inputs are changed and the code is run but the data label on one point, used to flag a key point on the curve, remains locked at the text it contained when the data series was formatted using the Select Data dialog.

The following code is used to force an update at the end of the VBA run and works on the numerical parts of the graph.

Application.Calculation = xlCalculationAutomatic
    Worksheets("Graph").Activate
    Application.Calculate

Open in new window


A snapshot of the graph is attached.
   
The vertical line on the graph is in the right place as is a single point, which has no marker, that I place above the top of the line.  The label is attached to the single point but it isn't changing even though the contents of the cell it refers to have changed. Labelling-bug.docx

How can I force the label to update?  I can't even do it manually without removing the label and remaking it.
Avatar of dlmille
dlmille
Flag of United States of America image

Can you mock up an example that we can look at?  I can come up with any number of reasons why its not working, but best to work from an example for efficiency sake - both yours and mine.

Thanks,

Dave
Avatar of sjgrey

ASKER

I saved the file and reopened it and the label does update now but the chart doesn't.  Here is a skeleton of the code.

Sub Output()
    
    
    Application.Calculation = xlCalculationManual    
'    Stops the graph from updating as each of the 1000 points is added to the sheet
    
'   Calculate and write the 1000 points into the Graph worksheet

    ...
    
'   Set the label for the percentile marker in the cell B3 which the data label is referred to

    Worksheets("Graph").Activate
    Cells(3, 2).Value = "P" & Format([n15] * 100, "##") & "=$" & Format([n16], "#0.0") & "M"
    Cells(3, 2).Characters(Start:=2, Length:=2).Font.Subscript = True

    Application.Calculation = xlCalculationAutomatic
    Worksheets("Graph").Activate
    Application.Calculate
    
End Sub

Open in new window


What happens now is:
1  The marker text is updated and the marker moves when its input values are changed, all as required but it wasn't doing this a while ago
2  The main graph points, the 1000 pairs that form the main plot, are calculated and placed in the Graph worksheet but the graph doesn't update until I run the code a second time

I'm trying to prevent the graph from updating while I write out the graph points as it slows the process down a lot, then update the graph and return the spreadsheet to automatic recalculation.

It seems at the moment that it is behaving eratically and I am wondering if there are any timing issues that come into play when, for instance, Activate and Calculate are used too soon one after the other.

I realsie it's probably not that simple though.
activate and calculate should have no timing issues.  Activating the chart is not what makes it update, but calculate is.  You can hit F9 just as easily, but understand you want that automatic.

Do me a favor - after you run this macro, select the chart and check that it is pointing to the series of data that you're updating with your macro.

Dave
Avatar of sjgrey

ASKER

Yes the data points are being written into the sheet

This has to have something to do with the recalc feature I think

Pressing f9 has no effect, only re-running the macro, which accesses another sheet for inputs then the Graph sheet to write the graph, fixes the graph update

I checked that the Excel options show Auto Recalc after the macro has run and it's all as expected

This is all a bit odd
So - you have VERIFIED that the graph is actually pointing to the data you're updating (see select data) and yet the graph is not reflecting those values?

And if you turn calc to automatic (even if slow) it DOES update the graph?

If this is the case, that's curious.  I've recently had similar instances of this today (not to move suspicions in this direction too hastily, it boggles the mind that you answer my first two questions as Yes!).

I would reboot.  I would turn calcs on and test.  Then turn calcs back off and test.  Then, I would suggest remapping the graph - delete and recreate.

Be sure to save backups!

Dave
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

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
Avatar of sjgrey

ASKER

Thanks - late now.  BAck tomorrow
Avatar of sjgrey

ASKER

That did it

I don't know how they were tunred off but switching them on fixed it

Thanks
Avatar of sjgrey

ASKER

After all that the problem returned later but I found a suggestion to use     Application.CalculateFullRebuild and that fixed it.

It's only a relatively small spreadsheet so a complete recalc doesn't take long
very interesting items we came up with re: bag of tricks....

Dave