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”.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!


<<Return to VBA Examples

countif
countif
countif
countif
countif
countif

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)