Solved

Reformat Data Labels using VBA

Posted on 2011-09-17
2
536 Views
Last Modified: 2012-05-12
Dear Experts:

the attached sample file shows bar charts where ...
... the DATA LABELS contain the category name as well as the values separated by a semicolon. Position is 'Outside End'

Is it possible to manipulate the data labels of the charts in the following way, using VBA:
All data labels where ...
.. the category name is 1 and 2 have to be positioned inside ('Inside End') and ...
... the font color has to be changed to white. The other ones have to be left untouched.

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

Regards, Andreas

 DataLabels-Reformat.xlsm
0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 500 total points
ID: 36555322
AndreasHermle,

It looks like this should do it:

Dim c As Excel.Chart
Dim dl As Excel.DataLabel
Set c = {reference to the chart to update}
Set dl = c.SeriesCollection(1).Points(1).DataLabel
dl.Position = xlLabelPositionInsideEnd
dl.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = vbWhite

Set dl = c.SeriesCollection(1).Points(2).DataLabel
dl.Position = xlLabelPositionInsideEnd
dl.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = vbWhite

Set dl = Nothing
Set c = Nothing

Open in new window

HTH,
pT72
0
 

Author Comment

by:AndreasHermle
ID: 36556389
Hi pT72:

great job, exactly like I wanted it.

I slightly tweaked the code since to be able to apply it to all the charts of the active worksheet (see below).

Thank you very much for your professional help.

Regards, Andreas
Sub Reformat_Data_Labels()

Dim dl As Excel.DataLabel
Dim myChtObj As ChartObject

For Each myChtObj In ActiveSheet.ChartObjects
        Set dl = myChtObj.Chart.SeriesCollection(1).Points(1).DataLabel
        dl.Position = xlLabelPositionInsideEnd
        dl.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = vbWhite
        Set dl = myChtObj.Chart.SeriesCollection(1).Points(2).DataLabel
        dl.Position = xlLabelPositionInsideEnd
        dl.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = vbWhite
Next

End Sub

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

773 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