VBA – Create a Bar Chart
Create Bar Chart in VBA
The following tutorial will describe how to create a bar chart using VBA.
Steps:
1. Enter the VBA project window by right clicking on a sheet name and selecting “View Code” or by selecting “ALT, F11”.
2. On the right hand side, right click on your project name and select inset “module”.
3. Copy and paste the following code into the new module you just created:
Sub MakeChart()
Dim myRange As Range
Set myRange = Application.InputBox _
(Prompt:="Select chart inputs", Type:=8)
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=myRange, _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
End Sub
4. Click on the save button.
5. Click on the little Excel icon on the top right under the “File” menu to exit the VBA project window and to return to Excel.
6. Next run the macro by pressing “Alt F8” to bring up the list of macro’s available and selecting “MakeChart”.