Solved

Reformat Data Labels using VBA

Posted on 2011-09-17
2
541 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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 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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

830 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