{"id":1478,"date":"2013-12-13T03:16:39","date_gmt":"2013-12-13T03:16:39","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=1478"},"modified":"2019-04-19T07:54:11","modified_gmt":"2019-04-19T07:54:11","slug":"excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/","title":{"rendered":"Excel 2010 VBA  Lesson 23: The List Box, Combo Box and Toggle Button"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-22-working-with-check-box-and-option-button\/\">[Lesson 22]<\/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-24-creating-charts-and-graphs\/\">[Lesson 24]<\/a><\/strong><\/h4>\n\n\n\n<p>We have learned how to work with check boxes, option buttons, and text boxes in Excel 2010 &nbsp;VBA &nbsp;in the previous lessons. We shall continue to learn how to manipulate other controls in Excel VBA 2010 in this lesson. In this lesson, we will deal with List Box, Combo Box, and Toggle Button.<\/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\">23.1 List Box<\/h4>\n\n\n\n<p>The function of the List Box is to present a list of items where the user can click and select the items from the list. To add items to the list, we can use the <strong>AddItem<\/strong> method.<\/p>\n\n\n\n<p>To clear all the items in the List Box, you can use the <strong>Clear<\/strong> method. The usage of Additem method and the Clear method is shown Example 23.1.<\/p>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br>\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><br>\n<script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><br>\n<strong>Example 23.1<\/strong>\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n For x = 1 To 10\n  ListBox1.AddItem \u201cApple\u201d\n Next\nEnd Sub\n\nPrivate Sub CommandButton2_Click()\n For x = 1 To 10\n  ListBox1.Clear\n Next\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_figure23.1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"531\" height=\"483\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg\" alt=\"vba2010_figure23.1\" class=\"wp-image-1484\"\/><\/a><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Figure 23.1<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>23.2 Combo Box<\/strong><\/h4>\n\n\n\n<p>The function of the Combo Box is also to present a list of items where the user can click and select the items from the list. However, the user needs to click on the small arrowhead on the right of the combo box to see the items which are presented in a drop-down list. In order to add items to the list, you can also use the AddItem method.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 23.2<\/strong>\n<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n ComboBox1.Text = \u201cApple\u201d\n For x = 1 To 10\n  ComboBox1.AddItem \u201cApple\u201d\n Next\nEnd Sub\n\nPrivate Sub CommandButton2_Click()\nComboBox1.Clear\n End Sub\n<\/pre>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><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\"><br><script>&lt;br \/>     (adsbygoogle = window.adsbygoogle || []).push({});&lt;br \/><\/script><br><strong>The Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"540\" height=\"477\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.2.jpg\" alt=\"vba2010_figure23.2\" class=\"wp-image-1488\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Figure 23.2<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>23.3 Toggle Button<\/strong><\/h4>\n\n\n\n<p>Toggle button lets the user switches from one action to another alternatively. When the Toggle button is being depressed, the value is true and when it is not depressed, the value is false. By using the If and Else code structure, we can thus switch from one action to another by pressing the toggle button repeatedly.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 23.3<\/strong><\/h4>\n\n\n\n<p>In this example, the user can toggle between apple and orange as well as font colors.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub ToggleButton1_Click ()\nIf ToggleButton1.Value = True Then\n Cells (1, 1) = \u201cApple\u201d\n Cells (1, 1).Font.Color = vbRed\nElse\n Cells (1, 1) = \u201cOrange\u201d\n Cells (1, 1).Font.Color = vbBlue\nEnd If\nEnd Sub\n<\/pre>\n\n\n\n<p>View the animated image in Figure 23.3<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/toggle_button1.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p><br>\n<strong>Figure 23.3<\/strong><br>\n<script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br>\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><br>\n<script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><br>\n<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">&nbsp;&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-22-working-with-check-box-and-option-button\/\">[Lesson 22]<\/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-24-creating-charts-and-graphs\/\">[Lesson 24]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;[Lesson 22]&lt;&lt;[Table of Contents]&gt;&gt;[Lesson 24] We have learned how to work with check boxes, option buttons, and text boxes in Excel 2010 &nbsp;VBA &nbsp;in the previous lessons. We shall continue to learn how to manipulate other controls in Excel VBA 2010 in this lesson. In this lesson, we will deal with List Box, Combo Box, &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel 2010 VBA  Lesson 23: The List Box, Combo Box and Toggle Button&#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":[15],"tags":[53,52],"class_list":["post-1478","page","type-page","status-publish","hentry","category-buttons-and-boxes","tag-combobox","tag-listbox"],"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 23: The List Box, Combo Box and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This lesson explains how to work with the list box, combo box and toggle button in 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-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\" \/>\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 23: The List Box, Combo Box and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This lesson explains how to work with the list box, combo box and toggle button in excel 2010 VBA\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\" \/>\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:54:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"531\" \/>\n\t<meta property=\"og:image:height\" content=\"483\" \/>\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-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\",\"url\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\",\"name\":\"Excel 2010 VBA Lesson 23: The List Box, Combo Box and Toggle Button - 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-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg\",\"datePublished\":\"2013-12-13T03:16:39+00:00\",\"dateModified\":\"2019-04-19T07:54:11+00:00\",\"description\":\"This lesson explains how to work with the list box, combo box and toggle button in excel 2010 VBA\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg\",\"width\":531,\"height\":483},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel 2010 VBA Lesson 23: The List Box, Combo Box and Toggle Button\"}]},{\"@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 23: The List Box, Combo Box and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This lesson explains how to work with the list box, combo box and toggle button in 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-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/","og_locale":"en_US","og_type":"article","og_title":"Excel 2010 VBA Lesson 23: The List Box, Combo Box and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This lesson explains how to work with the list box, combo box and toggle button in excel 2010 VBA","og_url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2019-04-19T07:54:11+00:00","og_image":[{"width":531,"height":483,"url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.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-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/","url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/","name":"Excel 2010 VBA Lesson 23: The List Box, Combo Box and Toggle Button - 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-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg","datePublished":"2013-12-13T03:16:39+00:00","dateModified":"2019-04-19T07:54:11+00:00","description":"This lesson explains how to work with the list box, combo box and toggle button in excel 2010 VBA","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#primaryimage","url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_figure23.1.jpg","width":531,"height":483},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-201-lesson-23-working-with-list-box-combo-box-and-toggle-button\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel 2010 VBA Lesson 23: The List Box, Combo Box and Toggle Button"}]},{"@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\/1478","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=1478"}],"version-history":[{"count":45,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1478\/revisions"}],"predecessor-version":[{"id":3332,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1478\/revisions\/3332"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=1478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=1478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=1478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}