{"id":548,"date":"2013-03-03T14:47:03","date_gmt":"2013-03-03T14:47:03","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=548"},"modified":"2020-04-23T10:58:20","modified_gmt":"2020-04-23T10:58:20","slug":"excel-vba-lesson-23-listbox-combobox","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-23-listbox-combobox\/","title":{"rendered":"Excel VBA Lesson 23: Working with ListBox, ComboBox and Toggle Button"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-22-checkbox\/\">&lt;&lt;Lesson 22&gt;&gt;<\/a> <a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\">[Contents]<\/a> <a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-24-creating-charts-graphs-excel-vba\/\">&lt;&lt;Lesson 24&gt;&gt;<\/a><\/strong><\/h4>\n\n\n\n<p>We have learned how to work with check boxes, option buttons and text boxes in Excel VBA in the previous lesson. We shall continue to learn how to manipulate other Excel VBA controls in this lesson.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>23.1 The ListBox<\/strong><\/h3>\n\n\n\n<p>The function of the ListBox 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 AddItem method.<\/p>\n\n\n\n<p>To clear all the items in the List Box, you can use the Clear method. The usage of Additem method and the Clear method is illustrated in Example 19.1 and The output is as shown in Figure 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><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 23.1<\/strong><\/h4>\n\n\n\n<p>Private Sub CommandButton1_Click()<br>\nFor x = 1 To 10<br>\nListBox1.AddItem &#8220;Apple&#8221;<br>\nNext<br>\nEnd Sub<br>\nPrivate Sub CommandButton2_Click()<br>\nFor x = 1 To 10<br>\nListBox1.Clear<br>\nNext<br>\nEnd Sub<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"360\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg\" alt=\"Excel VBA\" class=\"wp-image-552\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Figure 23.1<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>23.2 ComboBox<\/strong><\/h4>\n\n\n\n<p>The function of the ComboBox 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. The usage involving ComboBox is as shown in Example 19.2 and the output is as shown in Figure 19.2.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 23.2<\/strong><\/h4>\n\n\n\n<p>Private Sub CommandButton1_Click()<br>\nComboBox1.Text = &#8220;Apple&#8221;<br>\nFor x = 1 To 10<br>\nComboBox1.AddItem &#8220;Apple&#8221;<br>\nNext<br>\nEnd Sub<br>\nPrivate Sub CommandButton2_Click()<br>\nComboBox1.Clear<br>\nEnd Sub<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>\n<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"348\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.2.jpg\" alt=\"Excel vba Figure19.2\" class=\"wp-image-553\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Figure 23.2<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>23.3 Toggle Button<\/strong><\/h3>\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 activity 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.<\/p>\n\n\n\n<p>Private Sub ToggleButton1_Click ()<br>\nIf ToggleButton1.Value = True Then<br>\nCells (1, 1) = &#8220;Apple&#8221;<br>\nCells (1, 1).Font.Color = vbRed<br>\nElse<br>\nCells (1, 1) = &#8220;Orange&#8221;<br>\nCells (1, 1).Font.Color = vbBlue<br>\nEnd If<br>\nEnd Sub\n<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/toggle_button1.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"283\" height=\"360\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/toggle_button1.gif\" alt=\"toggle_button\" class=\"wp-image-557\"\/><\/a><\/figure><\/div>\n\n\n\n<p>View the animated image in Figure 23.3<strong>Figure 23.3<\/strong><\/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<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-22-checkbox\/\">&lt;&lt;Lesson 22&gt;&gt;<\/a> <a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\">[Contents]<\/a> <a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-24-creating-charts-graphs-excel-vba\/\">&lt;&lt;Lesson 24&gt;&gt;<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt;Lesson 22&gt;&gt; [Contents] &lt;&lt;Lesson 24&gt;&gt; We have learned how to work with check boxes, option buttons and text boxes in Excel VBA in the previous lesson. We shall continue to learn how to manipulate other Excel VBA controls in this lesson. 23.1 The ListBox The function of the ListBox is to present a list of &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-23-listbox-combobox\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel VBA Lesson 23: Working with ListBox, ComboBox 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":[],"class_list":["post-548","page","type-page","status-publish","hentry","category-buttons-and-boxes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Excel VBA Lesson 23: Working with ListBox, ComboBox and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This Excel VBA lesson demonstrates how to work with the Excel VBA Controls\" \/>\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\/vba_lesson23.htm\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel VBA Lesson 23: Working with ListBox, ComboBox and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This Excel VBA lesson demonstrates how to work with the Excel VBA Controls\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/vba_lesson23.htm\" \/>\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=\"2020-04-23T10:58:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"357\" \/>\n\t<meta property=\"og:image:height\" content=\"360\" \/>\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-lesson-23-listbox-combobox\/\",\"url\":\"https:\/\/excelvbatutor.com\/vba_lesson23.htm\",\"name\":\"Excel VBA Lesson 23: Working with ListBox, ComboBox 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\/vba_lesson23.htm#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson23.htm#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg\",\"datePublished\":\"2013-03-03T14:47:03+00:00\",\"dateModified\":\"2020-04-23T10:58:20+00:00\",\"description\":\"This Excel VBA lesson demonstrates how to work with the Excel VBA Controls\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson23.htm#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/vba_lesson23.htm\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson23.htm#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg\",\"width\":357,\"height\":360,\"caption\":\"Excel VBA\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson23.htm#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel VBA Lesson 23: Working with ListBox, ComboBox 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 VBA Lesson 23: Working with ListBox, ComboBox and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This Excel VBA lesson demonstrates how to work with the Excel VBA Controls","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\/vba_lesson23.htm","og_locale":"en_US","og_type":"article","og_title":"Excel VBA Lesson 23: Working with ListBox, ComboBox and Toggle Button - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This Excel VBA lesson demonstrates how to work with the Excel VBA Controls","og_url":"https:\/\/excelvbatutor.com\/vba_lesson23.htm","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2020-04-23T10:58:20+00:00","og_image":[{"width":357,"height":360,"url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.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-lesson-23-listbox-combobox\/","url":"https:\/\/excelvbatutor.com\/vba_lesson23.htm","name":"Excel VBA Lesson 23: Working with ListBox, ComboBox 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\/vba_lesson23.htm#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson23.htm#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg","datePublished":"2013-03-03T14:47:03+00:00","dateModified":"2020-04-23T10:58:20+00:00","description":"This Excel VBA lesson demonstrates how to work with the Excel VBA Controls","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson23.htm#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/vba_lesson23.htm"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/vba_lesson23.htm#primaryimage","url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure19.1.jpg","width":357,"height":360,"caption":"Excel VBA"},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/vba_lesson23.htm#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel VBA Lesson 23: Working with ListBox, ComboBox 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\/548","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=548"}],"version-history":[{"count":28,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/548\/revisions"}],"predecessor-version":[{"id":3467,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/548\/revisions\/3467"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}