Creating a Chart Using the Chart Object : Chart « Excel « VBA / Excel / Access / Word






Creating a Chart Using the Chart Object

 
Sub CreateExampleChartVersionII() 
    Dim ws As Worksheet 
    Dim rgChartData As Range 
    Dim myChart As Chart 

    Set ws = ThisWorkbook.Worksheets("Basic Chart") 
    Set rgChartData = ws.Range("B1").CurrentRegion 
    Set myChart = Charts.Add 
    Set myChart = myChart.Location(xlLocationAsObject, ws.Name) 

    With myChart 
        .SetSourceData rgChartData, xlColumns 
        .HasTitle = True 
        .ChartTitle.Caption = "Version II" 
        .ChartType = xlColumnClustered 

        With .Axes(xlCategory) 
            .HasTitle = True 
            .AxisTitle.Caption = "Year" 
        End With 

        With .Axes(xlValue) 
            .HasTitle = True 
            .AxisTitle.Caption = "GDP in billions of $" 
        End With 

    End With 

    Set myChart = Nothing 
    Set rgChartData = Nothing 
    Set ws = Nothing 
End Sub 

 








Related examples in the same category

1.Creating a New Chart Using the ChartWizard Method
2.Creating a Chart
3.Creating a Chart on an Existing Worksheet
4.Specifying the Source Data for the Chart by using the SetSourceData method of the Chart object
5.Specifying the Chart Type
6.Adding a New Series to the chart identified by the object variable myChart, drawing the data from the range C4:K4 on the active worksheet in the active workbook, using rows:
7.Extending an Existing Series in the chart identified by the object variable myChart using the data in the cells P3:P8 on the worksheet named Chart Data:
8.Creating a New Series, use the NewSeries method with the SeriesCollection collection.
9.Creating Charts
10.Creating an Embedded Chart
11.Add Chart
12.Select a chart object
13.Get Chart sheet
14.Reference Char object from ActiveSheet
15.Get Embedded Charts
16.Inserts a chart before each sheet
17.Inserts a chart before each sheet 2
18.Determining a chart's source data
19.Get Chart SeriesCollection value
20.Retrieving data point labels from field names in the worksheet
21.Show chart
22.Automatically generating a chart without user interaction
23.Producing an Excel worksheet on a Word 2000 document
24.Insert two chart sheets after the last worksheet in the active workbook. The chart sheets receive default names, such as Chart1 and Chart2:
25.Use For Each to loop through all chart objects
26.Activates the ChartObject named Chart 1
27.Modifying the chart type
28.To ensure that a chart is selected, you can add a statement to determine if a chart is active.
29.In most cases you can avoid using the worksheet Index property
30.Insert chart sheets after each worksheet
31.Adding a Chart Sheet Using VBA Code
32.convert an existing chart to use arrays instead of cell references and make it independent of the original data
33.add the data labels using the following code:
34.Referencing Charts and Chart Objects in VBA Code
35.Specify Exact Location