{"id":1212,"date":"2013-12-10T13:01:41","date_gmt":"2013-12-10T13:01:41","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=1212"},"modified":"2020-04-24T11:56:39","modified_gmt":"2020-04-24T11:56:39","slug":"excel-vba-lesson-11-decision-making-2-select-case-end-select","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/","title":{"rendered":"Excel 2010 VBA Lesson 11: Using Select Case"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-10-decision-making-1-if-then-else\/\">[Lesson 10]<\/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-12-looping\/\">[Lesson 12]<\/a><\/strong><\/h4>\n\n\n\n<p>In the previous lesson, we have learned how to use&nbsp;&nbsp;<strong>If\u2026.Then\u2026.Else<\/strong> statement. However, for multiple options, the If\u2026Then\u2026Else structure could become too bulky and difficult to debug. Fortunately, Excel &nbsp;2010 VBA provides another way to handle complex multiple-choice cases, that is, the <strong>Select Case&#8230;End Select<\/strong> decision structure. The structure of Select Case&#8230;End Select is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Select Case variable<br>Case value 1<br>Statement<br>Case value 2<br>Statement<br>Case value 3<br>Statement<br>.<br>.<br>Case Else<br>End Select<\/pre>\n\n\n\n<p>\n\nWe shall demonstrate the use of Select Case\u2026End Select in the following examples:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example 11.1<\/h4>\n\n\n\n<p>In this example, we want to automatically assign a remark in relation to a certain examination grade. For example, if the grade is A, we shall assign remark as High distinction, A- as distinction and so forth. To enter the code, start Excel 2010 then place a command button onto the spreadsheet and click on it to launch the Excel 2010 VBA &nbsp;editor.<\/p>\n\n\n\n<p><strong>The code:<\/strong>\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n\nDim grade As String\nDim grade As String\n grade = InputBox(\"Enter the grade(A, A-, B, C, E or F\")\nSelect Case grade\n Case \"A\"\n  MsgBox \"High Distinction\"Case \"A-\"\n  MsgBox \"Distinction\"\n Case \"B\"\n  MsgBox \"Credit\"\n Case \"C\"\n  MsgBox \"Pass\"\n Case Else\n  MsgBox \"Fail\"\nEnd Select\n\nEnd Sub\n<\/pre>\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\">Example 11.2<\/h4>\n\n\n\n<p>In this example, we shall show you how to process the grades of students according to the marks given. For example, if a student\u2019s mark is 85, the corresponding grade is A and if the mark is 20 the grade will be F and so forth.&nbsp;We can use the statement case&nbsp;<i>value1<\/i>&nbsp;to&nbsp;<i>value 2<\/i>&nbsp; to specify the range of values that fulfill the particular case.<\/p>\n\n\n\n<p>You should also include the error case where the values entered are out of the range or invalid. For example, if the examination mark is from 0 to 100, then any value out of this range is invalid.<br>\n<strong>The code:<\/strong>\n<\/p>\n\n\n\n<div id=\"mycontent\" style=\"border-bottom: 1px #3399ff solid; border-top: 1px #3399ff solid; padding-bottom: 0px;\">\n<div class=\"column1\" style=\"font-size: 90%; line-height: 90%; padding-left: 10px; padding-top: 5px;\">\n<pre style=\"font-size: 110%; width: 80%;\">Private Sub CommandButton1_Click()\n\nDim mark As Single\nDim grade As String\n mark = InputBox(\"Enter the mark\")\nSelect Case mark\n Case 0 To 29\n  grade = \"F\"\n Case 30 To 49\n  grade = \"E\"\n Case 50 To 59\n  grade = \"D\"\n Case 60 To 69\n  grade = \"C\"\n Case 70 To 79\n  grade = \"B\"\n Case 80 To 100\n  grade = \"A\"\n Case Else\n  grade = \"Error!\"\nEnd Select\n MsgBox grade\n\nEnd Sub\n<\/pre>\n<\/div>\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><h4 style=\"text-align: center;\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-10-decision-making-1-if-then-else\/\">[Lesson 10]<\/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-12-looping\/\">[Lesson 12]<\/a><\/strong><\/h4>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;[Lesson 10]&lt;&lt;[Table of Contents]&gt;&gt;[Lesson 12] In the previous lesson, we have learned how to use&nbsp;&nbsp;If\u2026.Then\u2026.Else statement. However, for multiple options, the If\u2026Then\u2026Else structure could become too bulky and difficult to debug. Fortunately, Excel &nbsp;2010 VBA provides another way to handle complex multiple-choice cases, that is, the Select Case&#8230;End Select decision structure. The structure of Select &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel 2010 VBA Lesson 11: Using Select Case&#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":[5],"tags":[],"class_list":["post-1212","page","type-page","status-publish","hentry","category-decison-making"],"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 11: Using Select Case - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This lesson illustrates the use of select case....end select to write decision-making code in excel 2010 VBA.macro programming\" \/>\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-lesson-11-decision-making-2-select-case-end-select\/\" \/>\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 11: Using Select Case - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This lesson illustrates the use of select case....end select to write decision-making code in excel 2010 VBA.macro programming\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/\" \/>\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-24T11:56:39+00:00\" \/>\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-11-decision-making-2-select-case-end-select\/\",\"url\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/\",\"name\":\"Excel 2010 VBA Lesson 11: Using Select Case - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"isPartOf\":{\"@id\":\"https:\/\/excelvbatutor.com\/#website\"},\"datePublished\":\"2013-12-10T13:01:41+00:00\",\"dateModified\":\"2020-04-24T11:56:39+00:00\",\"description\":\"This lesson illustrates the use of select case....end select to write decision-making code in excel 2010 VBA.macro programming\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel 2010 VBA Lesson 11: Using Select Case\"}]},{\"@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 11: Using Select Case - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This lesson illustrates the use of select case....end select to write decision-making code in excel 2010 VBA.macro programming","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-lesson-11-decision-making-2-select-case-end-select\/","og_locale":"en_US","og_type":"article","og_title":"Excel 2010 VBA Lesson 11: Using Select Case - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This lesson illustrates the use of select case....end select to write decision-making code in excel 2010 VBA.macro programming","og_url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2020-04-24T11:56:39+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/","url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/","name":"Excel 2010 VBA Lesson 11: Using Select Case - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","isPartOf":{"@id":"https:\/\/excelvbatutor.com\/#website"},"datePublished":"2013-12-10T13:01:41+00:00","dateModified":"2020-04-24T11:56:39+00:00","description":"This lesson illustrates the use of select case....end select to write decision-making code in excel 2010 VBA.macro programming","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-11-decision-making-2-select-case-end-select\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel 2010 VBA Lesson 11: Using Select Case"}]},{"@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\/1212","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=1212"}],"version-history":[{"count":69,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1212\/revisions"}],"predecessor-version":[{"id":3481,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1212\/revisions\/3481"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=1212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=1212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=1212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}