QP School
Chart methods in VBA - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48)
+--- Thread: Chart methods in VBA (/showthread.php?tid=5220)



Chart methods in VBA - Qomplainerz - 07-27-2023

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