{"id":1249,"date":"2013-12-10T14:25:12","date_gmt":"2013-12-10T14:25:12","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=1249"},"modified":"2019-04-19T07:42:42","modified_gmt":"2019-04-19T07:42:42","slug":"excel-vba-2010-lesson-13-do-loop","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/","title":{"rendered":"Excel 2010 VBA Lesson 13: Do&#8230;Loop"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-12-looping\/\">[Lesson 12]<\/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-14-errors-handling\/\">[Lesson 14]<\/a><\/strong><\/h4>\n\n\n\n<p>In this lesson, you will learn about another looping method know as the Do Loop in Excel 2010 VBA. There are four ways you can use the Do&#8230;Loop, as shown below:<\/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<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(i) Do...Loop While<br>(ii) Do until...Loop<br>(iii) Do while...Loop<br>(iv) Do...Loop until<\/pre>\n\n\n\n<p>\nWe shall illustrate the four structures of Do&#8230;Loop in the following examples:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example 13.1<\/h4>\n\n\n\n<p>Arranging numbers in ascending order\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()<br>Dim counter As Integer<br>Do<br>counter = counter + 1<br>Cells(counter, 1) = counter<br>Loop While counter &lt; 10<br>End Sub<\/pre>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\">In this example, the program will keep on adding 1 to the preceding counter value as long as the counter value is less than 10. It displays 1 in cells(1,1), 2 in cells(2,1)\u2026.. until 10 in cells (10,1).<\/p>\n\n\n\n<p><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_fig13.1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"381\" height=\"441\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg\" alt=\"vba2010_fig13.1\" class=\"wp-image-1252\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Figure 13.1<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 13.2<\/strong><\/h4>\n\n\n\n<p>Arranging numbers in descending order\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\nDim counter As Integer\nDo Until counter = 10\n counter = counter + 1\n Cells(counter, 1) = 11 \u2013 counter\nLoop\nEnd Sub\n<\/pre>\n\n\n\n<p>In this example, the program will keep on adding 1 to the preceding counter value until the counter value reaches 10. It displays 10 in cells(1,1), 9&nbsp; in cells(2,1)\u2026.. until 1 in cells (10,1).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"426\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.2.jpg\" alt=\"vba2010_fig13.2\" class=\"wp-image-1253\"\/><\/a><\/figure><\/div>\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 13.3<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\nDim counter , sum As Integer\n\u2018To set the alignment to center\n Range(\u201cA1:C11\u2033).Select\nWith Selection\n .HorizontalAlignment = xlCenter\nEnd With\n\nCells(1, 1) = \u201cX\u201d\nCells(1, 2) = \u201cY\u201d\nCells(1, 3) = \u201cX+Y\u201d\n\nDo While counter &lt; 10\n counter = counter + 1\n Cells(counter + 1, 1) = counter\n Cells(counter + 1, 2) = counter * 2\n sum = Cells(counter + 1, 1) + Cells(counter + 1, 2)\n Cells(counter + 1, 3) = sum\nLoop\nEnd Sub\n<\/pre>\n\n\n\n<p>In this example, the program will display the values of X in cells(1,1) to cells(11,1). The value of Y is X*2 and the values are displayed in column 2, i.e. from cells(2,1) to cells(2,11). Finally, it shows the values of X+Y in column 3, i.e. from cells(3,1) to cells(3,11)<\/p>\n\n\n\n<p><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_fig13.4.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"345\" height=\"408\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.4.jpg\" alt=\"vba2010_fig13.4\" class=\"wp-image-1255\"\/><\/a><\/figure><\/div>\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\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-12-looping\/\">[Lesson 12]<\/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-14-errors-handling\/\">[Lesson 14]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;[Lesson 12]&lt;&lt;[Table of Contents]&gt;&gt;[Lesson 14] In this lesson, you will learn about another looping method know as the Do Loop in Excel 2010 VBA. There are four ways you can use the Do&#8230;Loop, as shown below: (i) Do&#8230;Loop While(ii) Do until&#8230;Loop(iii) Do while&#8230;Loop(iv) Do&#8230;Loop until We shall illustrate the four structures of Do&#8230;Loop in the &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel 2010 VBA Lesson 13: Do&#8230;Loop&#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,11],"tags":[],"class_list":["post-1249","page","type-page","status-publish","hentry","category-decison-making","category-loop"],"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 13: Do...Loop - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This lesson illustrates how to create do...loop code 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-2010-lesson-13-do-loop\/\" \/>\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 13: Do...Loop - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This lesson illustrates how to create do...loop code in excel 2010 VBA.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/\" \/>\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:42:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\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-13-do-loop\/\",\"url\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/\",\"name\":\"Excel 2010 VBA Lesson 13: Do...Loop - 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-13-do-loop\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg\",\"datePublished\":\"2013-12-10T14:25:12+00:00\",\"dateModified\":\"2019-04-19T07:42:42+00:00\",\"description\":\"This lesson illustrates how to create do...loop code in excel 2010 VBA.\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg\",\"width\":381,\"height\":441},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel 2010 VBA Lesson 13: Do&#8230;Loop\"}]},{\"@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 13: Do...Loop - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This lesson illustrates how to create do...loop code 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-2010-lesson-13-do-loop\/","og_locale":"en_US","og_type":"article","og_title":"Excel 2010 VBA Lesson 13: Do...Loop - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This lesson illustrates how to create do...loop code in excel 2010 VBA.","og_url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2019-04-19T07:42:42+00:00","og_image":[{"url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/","url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/","name":"Excel 2010 VBA Lesson 13: Do...Loop - 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-13-do-loop\/#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg","datePublished":"2013-12-10T14:25:12+00:00","dateModified":"2019-04-19T07:42:42+00:00","description":"This lesson illustrates how to create do...loop code in excel 2010 VBA.","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#primaryimage","url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/12\/vba2010_fig13.1.jpg","width":381,"height":441},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-13-do-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel 2010 VBA Lesson 13: Do&#8230;Loop"}]},{"@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\/1249","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=1249"}],"version-history":[{"count":44,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1249\/revisions"}],"predecessor-version":[{"id":3323,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1249\/revisions\/3323"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=1249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=1249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}