Finance

Charts

Statistics

Macros

Search

Modifying an Embedded Chart In Excel VBA

The program to modify an embedded chart is structured similarly to the one used for modifying a chart sheet; it also consists of two parts. Below is the part that applies exclusively to embedded charts:

Sub ModifyEmbeddedChart()
    Dim CO As ChartObject
    Dim CH As Chart
    Set CO = ThisWorkbook.Worksheets("Sheet1").ChartObjects(1)
    CO.Left = 220
    CO.Top = 30
    CO.Width = 400
    CO.Height = 300
    Set CH = CO.Chart
    ChangeChart CH
    Set CH = Nothing
    Set CO = Nothing
End Sub

Explanation:
A variable of type ChartObject is declared and assigned to the first chart frame on the worksheet named « Sheet1 » in the workbook.

Next, a variable of type Chart is declared and assigned the chart contained within this chart frame.

For embedded charts, it can be useful to adjust the position and size of the chart frame. This is done by modifying the Left, Top, Width, and Height properties of the ChartObject.

Finally, the (previously introduced) procedure ChangeChart() is called, with the reference to the chart passed as a parameter to apply the desired modifications.

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx