{"id":1500,"date":"2013-12-13T04:47:00","date_gmt":"2013-12-13T04:47:00","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=1500"},"modified":"2019-04-19T07:55:21","modified_gmt":"2019-04-19T07:55:21","slug":"excel-vba-2010-lesson-24-creating-charts-and-graphs","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/","title":{"rendered":"Excel 2010 VBA Lesson 24: Creating Charts and Graphs"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\">[Lesson 23]<\/a>&lt;&lt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-tutorial\/\">[Table of Contents]<\/a>&gt;&gt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-25-creating-animation-in-excel-vba-2010\/\">[Lesson 25]<\/a><\/strong><\/h4>\n\n\n\n<p>In Excel 2010 &nbsp;VBA, we can write code to create charts and graphs easily based on the data on the spreadsheet. Excel 2010 VBA has made charting engine as part of the Shape object. It is also an object by itself. &nbsp;We can create charts on a sheet of their own or embed them into an existing worksheet. The chart sheet is the Chart object whereas the embedded chart is part of the shape collection for the worksheet.<\/p>\n\n\n\n<script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h4 class=\"wp-block-heading\">24.1 Creating a Pie Chart<\/h4>\n\n\n\n<p>To create a pie chart in a spreadsheet, first of all, you need to enter a range of data in a spreadsheet. After entering the data, you need to name the range by right-clicking the range and clicking defines name in the pop-up menu. Name the chart MyChart<\/p>\n\n\n\n<p>Now insert a command button and then click it to enter the following code in the Excel VBA 2010 editor<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n ActiveSheet.Shapes.AddChart.Select\n ActiveSheet.Shapes(1).Top = 10\n ActiveSheet.Shapes(1).Left = 10\n ActiveChart.ChartType = xl3DPie\n ActiveChart.PlotArea.Select\n ActiveChart.SetSourceData Source:=Range(\"MyChart\")\n ActiveChart.HasTitle = True\n ActiveChart.ChartTitle.Text = \"My Chart\"\nEnd Sub\n<\/pre>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br><ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins><br><script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><br>The Output<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"591\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg\" alt=\"vba2010_Figure24.1\" class=\"wp-image-1508\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Figure 24.1: Pie Chart<\/strong><\/p>\n\n\n\n<p>To separate the pie chart into slices (The technical term is explode), you can add this line to the code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ActiveChart.SeriesCollection(1).Explosion = 10\n<\/pre>\n\n\n\n<p>As there are five sectors, setting the explosion value to 10 explode all slices. You will get the following chart:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure24.4.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"492\" height=\"309\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure24.4.jpg\" alt=\"vba2010_figure24.4\" class=\"wp-image-1519\"\/><\/a><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Figure 24.2<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>23.2 Creating a Bar Graph<\/strong><\/h4>\n\n\n\n<p>To draw a bar graph, you just need to change the ChartType to&nbsp;&nbsp;xl3DColumn.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton2_Click()ActiveSheet.Shapes.AddChart.Select\n ActiveSheet.Shapes(1).Top = 10\n ActiveSheet.Shapes(1).Left = 10\n ActiveChart.ChartType = xl3DColumn\n ActiveChart.PlotArea.Select\n ActiveChart.SetSourceData Source:=Range(\"MyChart\")\n ActiveChart.HasTitle = True\n ActiveChart.ChartTitle.Text = \"My Chart\"\nEnd Sub\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure24.2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"594\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure24.2.jpg\" alt=\"vba2010_figure24.2\" class=\"wp-image-1510\"\/><\/a><\/figure><\/div>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\">&lt;<\/script><strong>Figure 24.3<\/strong><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\">br><\/script><\/p>\n\n\n\n<p>Excel VBA 2010 has built-in parameters to define the types of charts that can be drawn on a spreadsheet. &nbsp;You can refer to the parameters as the ChartType properties. The list of common properties for ChartType are listed below:<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><th>Property<\/th><th>Chart Type<\/th><\/tr><tr><td>xlArea<\/td><td>Area Chart<\/td><\/tr><tr><td>&nbsp;xlBar<\/td><td>&nbsp;Bar Chart<\/td><\/tr><tr><td>&nbsp;xlColumn<\/td><td>&nbsp;Column Chart<\/td><\/tr><tr><td>&nbsp;xlLine<\/td><td>&nbsp;Line Chart<\/td><\/tr><tr><td>&nbsp;xlPie<\/td><td>&nbsp;Pie Chart<\/td><\/tr><tr><td>&nbsp;xlXYScatter<\/td><td>&nbsp;XY Scatter Chart<\/td><\/tr><tr><td>&nbsp;xl3DArea<\/td><td>&nbsp;3D Area Chart<\/td><\/tr><tr><td>&nbsp;xl3DBar<\/td><td>&nbsp;3D Bar Chart<\/td><\/tr><tr><td>&nbsp;xl3DColumn<\/td><td>&nbsp;3D Column Chart<\/td><\/tr><tr><td>&nbsp;Xl3DLine<\/td><td>&nbsp;3D Line Chart<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>For example, if you change the ChartType property to xlLine using the code<\/p>\n\n\n\n<p>ActiveChart.ChartType = xlLine<\/p>\n\n\n\n<p>you will obtain a line graph as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure24.6.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"510\" height=\"318\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure24.6.jpg\" alt=\"vba2010_figure24.6\" class=\"wp-image-1521\"\/><\/a><\/figure><\/div>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br><ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins><br><script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">&nbsp;&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\">[Lesson 23]<\/a>&lt;&lt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-tutorial\/\">[Table of Contents]<\/a>&gt;&gt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-25-creating-animation-in-excel-vba-2010\/\">[Lesson 25]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;[Lesson 23]&lt;&lt;[Table of Contents]&gt;&gt;[Lesson 25] In Excel 2010 &nbsp;VBA, we can write code to create charts and graphs easily based on the data on the spreadsheet. Excel 2010 VBA has made charting engine as part of the Shape object. It is also an object by itself. &nbsp;We can create charts on a sheet of their &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel 2010 VBA Lesson 24: Creating Charts and Graphs&#8221;<\/span><\/a><\/p>\n","protected":false},"author":5012,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-1500","page","type-page","status-publish","hentry","category-charts"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Excel 2010 VBA Lesson 24: Creating Charts and Graphs - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This lesson illustrates how to draw charts and graphs using excel 2010 VBA\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel 2010 VBA Lesson 24: Creating Charts and Graphs - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This lesson illustrates how to draw charts and graphs using excel 2010 VBA\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-19T07:55:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"806\" \/>\n\t<meta property=\"og:image:height\" content=\"591\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/\",\"url\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/\",\"name\":\"Excel 2010 VBA Lesson 24: Creating Charts and Graphs - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"isPartOf\":{\"@id\":\"https:\/\/excelvbatutor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg\",\"datePublished\":\"2013-12-13T04:47:00+00:00\",\"dateModified\":\"2019-04-19T07:55:21+00:00\",\"description\":\"This lesson illustrates how to draw charts and graphs using excel 2010 VBA\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg\",\"width\":806,\"height\":591},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel 2010 VBA Lesson 24: Creating Charts and Graphs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/excelvbatutor.com\/#website\",\"url\":\"https:\/\/excelvbatutor.com\/\",\"name\":\"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"description\":\"Master Excel VBA with free tutorials, examples, and personalized guidance. Perfect for beginners and advanced users looking to automate Excel.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Excel 2010 VBA Lesson 24: Creating Charts and Graphs - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This lesson illustrates how to draw charts and graphs using excel 2010 VBA","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/","og_locale":"en_US","og_type":"article","og_title":"Excel 2010 VBA Lesson 24: Creating Charts and Graphs - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This lesson illustrates how to draw charts and graphs using excel 2010 VBA","og_url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2019-04-19T07:55:21+00:00","og_image":[{"width":806,"height":591,"url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg","type":"image\/jpeg"}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/","url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/","name":"Excel 2010 VBA Lesson 24: Creating Charts and Graphs - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","isPartOf":{"@id":"https:\/\/excelvbatutor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg","datePublished":"2013-12-13T04:47:00+00:00","dateModified":"2019-04-19T07:55:21+00:00","description":"This lesson illustrates how to draw charts and graphs using excel 2010 VBA","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#primaryimage","url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_Figure24.1.jpg","width":806,"height":591},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-24-creating-charts-and-graphs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel 2010 VBA Lesson 24: Creating Charts and Graphs"}]},{"@type":"WebSite","@id":"https:\/\/excelvbatutor.com\/#website","url":"https:\/\/excelvbatutor.com\/","name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"Master Excel VBA with free tutorials, examples, and personalized guidance. Perfect for beginners and advanced users looking to automate Excel.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/users\/5012"}],"replies":[{"embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/comments?post=1500"}],"version-history":[{"count":51,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1500\/revisions"}],"predecessor-version":[{"id":3484,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1500\/revisions\/3484"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=1500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=1500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=1500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}