VBA Tutorial
VBA Useful Resources
Selected Reading
- VBA - Userforms
- VBA - Programming Charts
- VBA - Text Files
- VBA - Excel Objects
- VBA - Error Handling
- VBA - Events
- VBA - Sub Procedure
- VBA - Functions
- VBA - Arrays
- VBA - Date and Time
- VBA - Strings
- VBA - Loops
- VBA - Decisions
- VBA - Operators
- VBA - Constants
- VBA - Variables
- VBA - Input Box
- VBA - Message Box
- VBA - Macro Comments
- VBA - Excel Terms
- VBA - Excel Macros
- VBA - Overview
- VBA - Home
VBA Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
VBA - Programming Charts
VBA - Programming Charts
Using VBA, you can generate charts based on certain criteria. Let us take a look at it using an example.
Step 1 − Enter the data against which the graph has to be generated.
![Graph in VBA](/vba/images/excel_graph_1.jpg)
Step 2 − Create 3 buttons - one to generate a bar graph, another to generate a pie chart, and another to generate a column chart.
![Graph in VBA](/vba/images/excel_graph_2.jpg)
Step 3 − Develop a Macro to generate each one of these type of charts.
Procedure to Generate Pie Chart Private Sub fn_generate_pie_graph_Cpck() Dim cht As ChartObject For Each cht In Worksheets(1).ChartObjects cht.Chart.Type = xlPie Next cht End Sub Procedure to Generate Bar Graph Private Sub fn_Generate_Bar_Graph_Cpck() Dim cht As ChartObject For Each cht In Worksheets(1).ChartObjects cht.Chart.Type = xlBar Next cht End Sub Procedure to Generate Column Graph Private Sub fn_generate_column_graph_Cpck() Dim cht As ChartObject For Each cht In Worksheets(1).ChartObjects cht.Chart.Type = xlColumn Next cht End Sub
Step 4 − Upon cpcking the corresponding button, the chart is created. In the following output, cpck on generate Pie Chart button.
![Graph in VBA](/vba/images/excel_graph_3.jpg)