Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

How to Create Charts in Excel Using Worksheet Data and VBA?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Excel is an important software provided by Microsoft Corporation. This software belongs to one of the major software suites Office 365. In this software suite, there are other software are present like Word, PowerPoint, etc. They are called Office 365, as this software are mostly used for office purpose. But now the world has changed a lot. After the Corona Pandemic, the world knows the positivity of using digital tools. Office 365 was not different from that. As a part of the software suite, Excel software also gains some importance from the users. They are not only used for official purposes. But they can also be used for school purposes. Excel is software that can able to store data in an effective form. So, searching for the data becomes more manageable in this software.

Excel has another great feature. It can be used to derive the charts from the provided data. The charts are helpful for analyzing any growth of the data. If there are thousands of data present, it is a difficult task to extract some analysis from that data. But if those data are converted to charts, then it will be easy to analyze those data. Excel sheet helps to do the same. Charts can be prepared whatever the number of data is present in the Excel sheet. The process of preparation of the charts can be done in two ways. In one case, users need to do operations on their own. On the other hand, users need to write a certain function to generate those things.

Creation of Charts in Excel using Worksheet Data

In this method, there is a need to have worksheet data. This is a simple method to create charts from the given data. This is the manual method. This means, there is no involvement of any code or automation is included. All the operations need to be executed by the user. Though it is executed by the user, still it is a lot easier than other processes. As this process can be done by any individual without having any issues or any previous knowledge.

Step 1: Users first need to have a set of data from creating the charts. They need to write all of them on the Excel worksheet. This is the simple process, they need to do. After that, users need to select the area from which they need to extract the chart. In the worksheet data, there might be some data that need to be excluded from the chart. So, users need to select the data that must be in the chart.



Step 2: Now, users need to press the Alt+F1 button simultaneously. As a result, promptly the data will be visible to the users in form of a chart. Now, users can drag the chart in any direction. Also, they can use it for some other software. This chart will help to analyze the data. This is a simple process.



Hence, we have successfully created a chart in Excel using worksheet data.

Creation of Charts in Excel using VBA Code

VBA code is a special type of programming language. But they are not considered conceptual programming langue like Python, Java, etc. This is the simple programming language that belongs to the software under Office 365. This means Word, Excel, etc. software can able to understand those. This is a programming language, that can be human-readable. Also, this helps to automate some tasks in the Excel file. This will also help to generate charts.

Step 1: Here also, users need to have some data to use the VBA code to generate the charts. Here for the demonstration purpose, a set of data is allocated.



Step 2: Users need to move to the Developer Tab. In this tab, users will find some more options. Among those options, one option will be Design Mode. Users need to click on that to open the VBA editor.

Note: If users are using some old version of Excel, then there might not be a tab called Developer. In those cases, users need to click Alt+F11 simultaneously. This will help to open the same VBA Window for editing purposes. So, there is no need to be worried for the users. Users might even use the Office 2007 Edition. But this process will work in every edition version.



Step 3: Now, users need to write a piece of code. This code might seem like an as difficult one. But analyzing this code step by step will help to understand the approach easily. Let us try to find the process step by step.

  1. Users first need to declare a subject. It is the same process that a programmer needs to do for writing programs in the C programming language. In C programming language, programmers used to write the main() function as the starting region. In this case, the “Sub” will act the same. Users need to declare access modifiers there as Java programming language. Also, users need to provide a name for it.
  2. Now, users need to declare a variable to do further operations. The declaration of the variable is done using the keyword “Dim” here. Now, users need to provide a variable name & join that variable for creating the chart.
  3. Now, users need to use the “Set” keyword to add the variable for the creation of the charts. This line helps to implement a chart using the variable that is declared.
  4. Now, users need to provide data to the variable. So, for providing the data, users need to use the “SetSourceData” keyword. Also, users need to provide the sheet name & range of the data by which the chart is going to be prepared. Users need to provide the “Sheet” name there. This is the simple sheet, not the worksheet.
  5. Now, the process is completed. It is time to end the process. Users need to use the “End” keyword there. This is the same process that any programmer needs to do in the C programming language using the ending brace.

VBA Code:

Private Sub Comm

Dim my_chart As Chart

Set my_chart = Charts.Add

my_chart.SetSourceData Sheets(“Sheet1”).Range(“A2:B14”)

End Sub



Step 4: Now, after the process is completed, users will find a play button on the upper side of the VBA Editor. Users need to click on that button to generate the charts from the written code.



Step 5: Now, the chart is available there in front of the users. Users can use this chart for any other software. Also, users can drag to any other position.



Hence, we have successfully created a chart in Excel using VBA Code.


Excel is a powerful software for managing a large scale of data. It is used for analyzing data in a small amount of time. Excel software is used to convert a series of data into another format. That is the reason, this software is used to generate charts from the data provided there. In this article, we have demonstrated the process to generate charts using the worksheet data. Along with that, we have discussed the method to use VBA code & implement charts from a given data. The step-by-step implementation process of the VBA code is also discussed here.

My Personal Notes arrow_drop_up
Last Updated : 01 Feb, 2023
Like Article
Save Article
Similar Reads
Related Tutorials