Solved

Looping thru the SeriesCollection and add data labels

Posted on 2011-03-01
4
922 Views
Last Modified: 2012-05-11
Dear Experts:

below code snippet creates ...
... Data labels just for just the first! data series of my stacked column chart and formats them

Is it possible to loop through the SeriesCollection and add/format datalabels for all of the Data Series (stacked column chart)?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Sub LoopingThruSeriesCollection()

Dim MyChtObj as ChartObject

With MyChtObj.Chart
    .SeriesCollection(1).ApplyDataLabels
          With .SeriesCollection(1).DataLabels
               .Position = xlLabelPositionInsideEnd
               .Font.Color = RGB(5, 5, 5)
               .Font.Name = "Verdana"
               .Font.Size = 6
               .NumberFormat = "#."
          End With
End With

Open in new window

0
Comment
Question by:AndreasHermle
  • 2
4 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 35009229
Untested, but see if this works:
Sub LoopingThruSeriesCollection()

Dim MyChtObj As ChartObject, i As Long

For i = 1 To ActiveSheet.ChartObjects.Count
    With ActiveSheet.ChartObjects(i).Chart
        .SeriesCollection(1).ApplyDataLabels
        With .SeriesCollection(1).DataLabels
             .Position = xlLabelPositionInsideEnd
             .Font.Color = RGB(5, 5, 5)
             .Font.Name = "Verdana"
             .Font.Size = 6
             .NumberFormat = "#."
        End With
    End With
Next i

End Sub

Open in new window

0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35009286
Sub LoopingThruSeriesCollection()

Dim MyChtObj as ChartObject
Dim ser as series

With MyChtObj.Chart
    for each ser in .SeriesCollection
       ser.applydatalabels
          With ser.DataLabels
               .Position = xlLabelPositionInsideEnd
               .Font.Color = RGB(5, 5, 5)
               .Font.Name = "Verdana"
               .Font.Size = 6
               .NumberFormat = "#."
          End With
   next ser
End With

Open in new window


I think.
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 35009326
Sorry, I completely failed to read the question properly!
0
 

Author Closing Comment

by:AndreasHermle
ID: 35014952
Dear rorya:
great, thank you very much for your professional help. Regards, Andreas
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

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…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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 …

746 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

11 Experts available now in Live!

Get 1:1 Help Now