Solved

run macro on selected charts (resizing the chart area as well as data labels)

Posted on 2014-01-20
4
1,424 Views
Last Modified: 2014-01-23
Dear Experts:

for the selected charts on the active worksheet I would like to run the following VBA macro:

- Resize the charts to Width of 5 cm and Height of 9 cm
- Increase the size of the chart labels (all of them are pie charts) to 10 pt and font type 'Times New Roman'

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

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

pls try

Sub Makro7() '
' Makro7 Makro
For Each wks In Workbooks
    wks.Activate
    For Each cht In ActiveSheet.ChartObjects
        'cht.Legend.Format.TextFrame2.TextRange.Font.Size = 10
        cht.Chart.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange.Font.Size = 10
        cht.Chart.ChartArea.Height = Application.CentimetersToPoints(5)
        cht.Chart.ChartArea.Width = Application.CentimetersToPoints(9)
    Next
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:AndreasHermle
Comment Utility
Hi Rgonzo,

thank you very much for your swift help. I will give your code a try soon, but as I can see all of the charts get worked on on the active worksheet.

I got charts on the active worksheet that should be left alone and only those charts that I selected by using the Shift-Key and clicking on them should be worked on. Is this possible, i.e. running the above macro just on selected charts ...

Regards, Andreas
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

pls try

Sub Makro7() '
' Makro7 Makro

For Each cht In Selection
    cht.Activate
    'cht.Legend.Format.TextFrame2.TextRange.Font.Size = 10
    cht.Chart.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange.Font.Size = 10
    cht.Chart.ChartArea.Height = Application.CentimetersToPoints(5)
    cht.Chart.ChartArea.Width = Application.CentimetersToPoints(9)
Next

End Sub

Open in new window

It is without test whether you select Charts or anything

Regards
0
 

Author Closing Comment

by:AndreasHermle
Comment Utility
Great, this did the trick. Thank you very much for your professional help. Regards,  Andreas
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
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…
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.

762 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

10 Experts available now in Live!

Get 1:1 Help Now