Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a pie-chart in excel using VBA

I am new to VBA and am trying to learn how to create a pie-chart out of certain values on the Excel spreadsheet. I know how to do the bar charts, but I was wondering whether you guys are aware of online resources or tutorials for this.

like image 874
Apollon1954 Avatar asked Nov 02 '10 23:11

Apollon1954


People also ask

How do I create a chart in Excel VBA?

Step 1: Start Sub Procedure. Step 2: Define the variable as Chart. Step 3: Since the chart is an object variable, we need to Set it. The above code will add a new sheet as a chart sheet, not a worksheet.


1 Answers

Tools -> Macro -> Record New Macro produces this code which you can then tweak to your specific needs:

Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:A4"), PlotBy:= _
    xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
ActiveChart.HasTitle = False
like image 58
mechanical_meat Avatar answered Sep 21 '22 00:09

mechanical_meat