Solved

Reformat Data Labels using VBA

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

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

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 …
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 …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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 …

740 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