Saturday, February 28, 2009

Excel VBA Macro: Creating a Chart

In this post, we will create a chart using Microsoft Excel VBA macro.

Embedded Chart

Use an embedded chart when you want the chart displayed as part of a worksheet along with the data and/or other charts. Here is the example to create an embedded chart:

Public Sub EmbeddedChart()
Dim myChartObject As ChartObject
Dim myChart As Chart
Set myChartObject = Worksheets("Sheet1").ChartObjects.Add(100, 150, 300, 225)
Set myChart = co.Chart
myChart.SetSourceData Source:=Worksheets("Sheet1").Range("A2:E6"), PlotBy:=xlRows
End Sub

Chart Sheets

Use a Chart Sheet when you want a chart displayed in different sheet.

Public Sub ChartSheet()
Dim mychart As Chart
Set mychart = ActiveWorkbook.Charts.Add
mychart.SetSourceData Source:=Worksheets("Sheet1").Range("A2:E6"), PlotBy:=xlRows
End Sub

Related posts:

If you like posts in this blog, you can to support me :)

No comments:

Post a Comment