QP School

Full Version: Chart methods in VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Description:

Charts are objects in Excel, and they have methods like ChartType, SetSourceData, and HasTitle.

Example:

Sub ExampleChartMethods()
    'Create a new chart
    Dim cht As Chart
    Set cht = Sheets("Sheet1").ChartObjects.Add(Left:=100, Width:=375, Top:=75, Height:=225).Chart

    'Set the chart type to a column chart
    cht.ChartType = xlColumnClustered

    'Set the chart data source
    cht.SetSourceData Source:=Sheets("Sheet1").Range("A1:B5")

    'Add a chart title
    cht.HasTitle = True
    cht.ChartTitle.Text = "Sales Data"
End Sub