Solved

Excel chart data label not updating

Posted on 2011-03-03
10
1,166 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:sjgrey
  • 5
  • 5
10 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 35033676
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
0
 
LVL 1

Author Comment

by:sjgrey
ID: 35034135
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.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35034226
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
0
 
LVL 1

Author Comment

by:sjgrey
ID: 35035076
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
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35035513
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
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 35035540
Do you have any other code behind that graph?  Also, is there any other code in your spreadsheet?  Are events turned off?

Try Application.EnableEvents = TRUE - not sure, but sometimes I get out of whack with a macro and events are off, then nothing seems to work correctly!


0
 
LVL 1

Author Comment

by:sjgrey
ID: 35036172
Thanks - late now.  BAck tomorrow
0
 
LVL 1

Author Closing Comment

by:sjgrey
ID: 35041095
That did it

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

Thanks
0
 
LVL 1

Author Comment

by:sjgrey
ID: 35041729
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
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35041764
very interesting items we came up with re: bag of tricks....

Dave
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

706 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

18 Experts available now in Live!

Get 1:1 Help Now