|Excel And SQL .com|
Home > VBA Macros
How to create a chart
Building charts is one of the strongest and most popular features of Microsoft Excel. If you have got data, what else is the best way to show it graphically using good looking line, bar or pie chart or graph. As it goes, picture is a worth a thousand words.
You can build aesthetically pleasing graphs in Excel using just a few lines of code and you have full flexibility to custimize these graphs using VBA code.
Sub Demo() 'Create some dummy data first to use to build our chart. Dim arrayProducts() As String Dim arraySales() As String arrayProducts = Split("Product:Apples:Berries:Bananas:Oranges", ":") arraySales = Split("Sales:100:150:300:400", ":") Range("A1:A5").Cells.Value = Application.Transpose(arrayProducts) Range("B1:B5").Cells.Value = Application.Transpose(arraySales) 'Now create a pie chart using the data created above Dim PieChart As Chart Dim BarChart As Chart Columns("A:B").Select Charts.Add ActiveChart.ChartType = xlPie End Sub
|© All Rights Reserved. ExcelAndSql.com|