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

x
?
Solved

Looping thru the SeriesCollection and add data labels

Posted on 2011-03-01
4
Medium Priority
?
976 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
[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
  • 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 2000 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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

721 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