Loading

Friday, February 27, 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


SHARE TWEET

Thank you for reading this article Excel VBA Macro: Creating a Chart With URL https://x-tutorials.blogspot.com/2009/02/excel-vba-macro-creating-chart.html. Also a time to read the other articles.

0 comments:

Write your comment for this article Excel VBA Macro: Creating a Chart above!