Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel chart data label not updating

Posted on 2011-03-03
10
Medium Priority
?
1,613 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
[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
  • 5
  • 5
10 Comments
 
LVL 42

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 42

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
Industry Leaders: 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!

 
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 42

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
 
LVL 42

Accepted Solution

by:
dlmille earned 2000 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 42

Expert Comment

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

Dave
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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

715 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