March 19, 2014

Create Charts Using Excel VBA

We can create charts using Excel VBA quickly and easily. Creating charts can be the starting point for creating dashboards. There are two types of charts in MS Excel: one type of chart is created on its own worksheet and is known as a chart object and the other type of chart is an embedded chart in the worksheet next to the data and is called a chartobject. Chart sheets are defined as members of the workbook charts collection. A chart embedded in a worksheet is a member of the worksheet chartobjects collection. This may sound a little confusing but as you work with the sample VBA codes you will understand this concept quickly.
Below is the code for creating a column chart on a separate chart sheet using VBA:

Sub createmychart()
Dim chart1 As Chart
Set chart1 = Charts.Add
chart1.SetSourceData Source:=Worksheets(“sheet1”).Range(“A1”).CurrentRegion, PlotBy:=xlColumns
chart1.ChartType = xlColumnClustered
End Sub

Watch the Excel training video:

Further reading:
Creating Charts in Excel 2003 Using Visual Basic for Applications Code

7 thoughts on “Create Charts Using Excel VBA

  1. Can you please tell how can I plot a graph of certain formula using and some values input in excel with micro. just like a program
    Please help

  2. I want the VBA code for automatic creation of charts for selected rows and columns using a single command button

  3. I have excel document with the the following header (serial #, old code, new code,status, location and room etc). I want to create a VB to sort out equipment that are ok and not ok in sheet 2 using the serial # or old code or new code to identify the equipment. Also indicating the location and room of the equipment.

Comments are closed.