{"id":551,"date":"2019-02-21T21:34:38","date_gmt":"2019-02-21T21:34:38","guid":{"rendered":"http:\/\/www.vbastring.com\/blog\/?p=551"},"modified":"2019-02-21T21:38:39","modified_gmt":"2019-02-21T21:38:39","slug":"how-to-repeat-tasks-with-your-vba-code","status":"publish","type":"post","link":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/","title":{"rendered":"How To Repeat Tasks With Your VBA Code"},"content":{"rendered":"<p>This post is actually an answer to a question on a youtube video<\/p>\n<blockquote><p>&#8220;I am facing one problem during working with excel, how do I solve below&#8230;.. Serial number in row:1,2,3,4&#8230;&#8230;&#8230;&#8230; Required no of repit :2,1,3,2&#8230;&#8230;&#8230;&#8230; Answer will be : 1,1,2,3,3,3,4,4&#8230;&#8230;.. How do I solve this problem??? Where one and another dejit will repit continuously.. Please help to find a way to solve this problem. Thank you.\ufeff&#8221;<\/p><\/blockquote>\n<p>Here is the setup:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png?resize=300%2C213\" alt=\"\" width=\"300\" height=\"213\" class=\"alignleft size-medium wp-image-554\" \/><\/a><\/p>\n<p><strong>For this we are going to use a for loop to loop the cells and another for loop to insert the results.<\/strong><\/p>\n<p>Paste this code into a module, and we&#8217;ll call it from a button on the worksheet.<\/p>\n<pre class=\"lang:vb decode:true \" >Sub Button1_Click()\r\n    Dim intValue As Integer\r\n    Dim intRowsToEvaluate As Integer\r\n        \r\n    Dim intRepeat As Integer\r\n    \r\n    Dim intResultRow As Integer\r\n    \r\n    intRowsToEvaluate = 20\r\n    \r\n    Dim intRow As Integer\r\n    \r\n    For intRow = 2 To intRowsToEvaluate\r\n        'get the value and the number of times to repeat the value.\r\n        intValue = Range(\"A\" &amp; intRow)\r\n        intRepeat = Range(\"B\" &amp; intRow)\r\n        \r\n        'get the last result row used\r\n        lngLastRow = FindLastRow(\"C\")\r\n        lngLastRow = lngLastRow + 1\r\n        \r\n        'enter the results\r\n        For intResultRow = 1 To intRepeat\r\n            Range(\"C\" &amp; lngLastRow) = intValue\r\n            lngLastRow = lngLastRow + 1\r\n        Next\r\n            \r\n    Next\r\n    \r\nEnd Sub\r\n\r\nFunction FindLastRow(WhichColumn As String) As Long\r\n\r\n    Dim lngLastRow As Long\r\n    \r\n    'move to the last row on the worksheet and find the last used cell.\r\n    \r\n    With ActiveSheet\r\n        lngLastRow = ActiveSheet.Cells(1048576, WhichColumn).End(xlUp).Row\r\n    End With\r\n\r\n    FindLastRow = lngLastRow\r\n\r\nEnd Function\r\n<\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code2.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code2-300x228.png?resize=300%2C228\" alt=\"\" width=\"300\" height=\"228\" class=\"alignleft size-medium wp-image-556\" \/><\/a><\/p>\n<p>****************************************************<\/p>\n<table border=\"1\" width=\"100%\">\n<tr>\n<td align=\"middle\">\n<div class=\"AW-Form-1094354588\"><\/div>\n<p><script type=\"text\/javascript\">(function(d, s, id) {\n    var js, fjs = d.getElementsByTagName(s)[0];\n    if (d.getElementById(id)) return;\n    js = d.createElement(s); js.id = id;\n    js.src = \"\/\/forms.aweber.com\/form\/88\/1094354588.js\";\n    fjs.parentNode.insertBefore(js, fjs);\n    }(document, \"script\", \"aweber-wjs-kkrwj13ov\"));\n<\/script>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>This post is actually an answer to a question on a youtube video &#8220;I am facing one problem during working with excel, how do I solve below&#8230;.. Serial number in row:1,2,3,4&#8230;&#8230;&#8230;&#8230; Required no of repit :2,1,3,2&#8230;&#8230;&#8230;&#8230; Answer will be : 1,1,2,3,3,3,4,4&#8230;&#8230;.. How do I solve this problem??? Where one and another dejit will repit continuously.. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Repeat Tasks With Your VBA Code - My Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Repeat Tasks With Your VBA Code - My Blog\" \/>\n<meta property=\"og:description\" content=\"This post is actually an answer to a question on a youtube video &#8220;I am facing one problem during working with excel, how do I solve below&#8230;.. Serial number in row:1,2,3,4&#8230;&#8230;&#8230;&#8230; Required no of repit :2,1,3,2&#8230;&#8230;&#8230;&#8230; Answer will be : 1,1,2,3,3,3,4,4&#8230;&#8230;.. How do I solve this problem??? Where one and another dejit will repit continuously.. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/\" \/>\n<meta property=\"og:site_name\" content=\"My Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-21T21:34:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-21T21:38:39+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"headline\":\"How To Repeat Tasks With Your VBA Code\",\"datePublished\":\"2019-02-21T21:34:38+00:00\",\"dateModified\":\"2019-02-21T21:38:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/\"},\"wordCount\":115,\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/\",\"name\":\"How To Repeat Tasks With Your VBA Code - My Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png\",\"datePublished\":\"2019-02-21T21:34:38+00:00\",\"dateModified\":\"2019-02-21T21:38:39+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png\",\"contentUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/21\\\/how-to-repeat-tasks-with-your-vba-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Repeat Tasks With Your VBA Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\",\"name\":\"My Blog\",\"description\":\"My WordPress Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/vbastring.com\\\/blog\"],\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Repeat Tasks With Your VBA Code - My Blog","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:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/","og_locale":"en_US","og_type":"article","og_title":"How To Repeat Tasks With Your VBA Code - My Blog","og_description":"This post is actually an answer to a question on a youtube video &#8220;I am facing one problem during working with excel, how do I solve below&#8230;.. Serial number in row:1,2,3,4&#8230;&#8230;&#8230;&#8230; Required no of repit :2,1,3,2&#8230;&#8230;&#8230;&#8230; Answer will be : 1,1,2,3,3,3,4,4&#8230;&#8230;.. How do I solve this problem??? Where one and another dejit will repit continuously.. [&hellip;]","og_url":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/","og_site_name":"My Blog","article_published_time":"2019-02-21T21:34:38+00:00","article_modified_time":"2019-02-21T21:38:39+00:00","og_image":[{"url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#article","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/"},"author":{"name":"admin","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"headline":"How To Repeat Tasks With Your VBA Code","datePublished":"2019-02-21T21:34:38+00:00","dateModified":"2019-02-21T21:38:39+00:00","mainEntityOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/"},"wordCount":115,"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/","url":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/","name":"How To Repeat Tasks With Your VBA Code - My Blog","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#primaryimage"},"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png","datePublished":"2019-02-21T21:34:38+00:00","dateModified":"2019-02-21T21:38:39+00:00","author":{"@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"breadcrumb":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#primaryimage","url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png","contentUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Repeat_Tasks_With_Your_VBA_Code-300x213.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/21\/how-to-repeat-tasks-with-your-vba-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vbastring.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Repeat Tasks With Your VBA Code"}]},{"@type":"WebSite","@id":"https:\/\/vbastring.com\/blog\/#website","url":"https:\/\/vbastring.com\/blog\/","name":"My Blog","description":"My WordPress Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vbastring.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/vbastring.com\/blog"],"url":"https:\/\/vbastring.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":5,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":563,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/551\/revisions\/563"}],"wp:attachment":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}