{"id":37667658,"url":"https://github.com/albertov5/tec-data-02-vba","last_synced_at":"2026-01-16T12:00:32.637Z","repository":{"id":48520415,"uuid":"513745861","full_name":"AlbertoV5/tec-data-02-vba","owner":"AlbertoV5","description":"Data Analytics Bootcamp","archived":false,"fork":false,"pushed_at":"2022-07-23T01:36:55.000Z","size":1853,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-04T18:11:45.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"VBScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlbertoV5.png","metadata":{"files":{"readme":"readme.html","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-14T03:26:36.000Z","updated_at":"2022-07-14T04:28:55.000Z","dependencies_parsed_at":"2022-08-30T19:12:14.298Z","dependency_job_id":null,"html_url":"https://github.com/AlbertoV5/tec-data-02-vba","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/AlbertoV5/tec-data-02-vba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertoV5%2Ftec-data-02-vba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertoV5%2Ftec-data-02-vba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertoV5%2Ftec-data-02-vba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertoV5%2Ftec-data-02-vba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlbertoV5","download_url":"https://codeload.github.com/AlbertoV5/tec-data-02-vba/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertoV5%2Ftec-data-02-vba/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-16T12:00:22.222Z","updated_at":"2026-01-16T12:00:32.547Z","avatar_url":"https://github.com/AlbertoV5.png","language":"VBScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003c!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"\u003e\n\u003chtml xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"\u003e\n\u003chead\u003e\n\u003c!-- 2022-07-14 Thu 22:55 --\u003e\n\u003cmeta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /\u003e\n\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\u003e\n\u003ctitle\u003eChallenge: Refactoring VBA Code\u003c/title\u003e\n\u003cmeta name=\"author\" content=\"Alberto Valdez\" /\u003e\n\u003cmeta name=\"generator\" content=\"Org Mode\" /\u003e\n\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"https://albertov5.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css\"/\u003e\n\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"https://albertov5.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css\"/\u003e\n\u003cscript src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"https://albertov5.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"https://albertov5.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cdiv id=\"content\" class=\"content\"\u003e\n\u003ch1 class=\"title\"\u003eChallenge: Refactoring VBA Code\u003c/h1\u003e\n\u003cdiv id=\"table-of-contents\" role=\"doc-toc\"\u003e\n\u003ch2\u003eTable of Contents\u003c/h2\u003e\n\u003cdiv id=\"text-table-of-contents\" role=\"doc-toc\"\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#org5abd25a\"\u003eOverview\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#org00a2e5b\"\u003eResults\u003c/a\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#orga91b696\"\u003eOriginal Code\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#orgfaa14e9\"\u003eRefactored Code\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#org2024f32\"\u003eConclusions\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#org138b540\"\u003eSummary\u003c/a\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#orga47a71c\"\u003eCons of refactoring code:\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#orga31af86\"\u003ePros of refactoring code:\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#orgb6b1278\"\u003eClosing Thoughts\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003ctable border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\"\u003e\n\n\n\u003ccolgroup\u003e\n\u003ccol  class=\"org-left\" /\u003e\n\u003c/colgroup\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd class=\"org-left\"\u003e\u003ca href=\"../readme.html\"\u003e\u0026lt;\u0026lt;Back\u003c/a\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003cdiv id=\"outline-container-org5abd25a\" class=\"outline-2\"\u003e\n\u003ch2 id=\"org5abd25a\"\u003eOverview\u003c/h2\u003e\n\u003cdiv class=\"outline-text-2\" id=\"text-org5abd25a\"\u003e\n\u003cp\u003e\nDuring this module, we managed to automate various basic Excel tasks using Visual Basic for Applications. The most important part of the process was that we managed to do it without focusing too much on the scripting language but rather the problems we wanted to solve.\n\u003c/p\u003e\n\n\u003cp\u003e\nNow that the mission is accomplished and the code works, we venture into optimization in order to make sure our code can cover more cases, particularly those cases where we have to work with data orders of magnitude bigger.\n\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\u003cdiv id=\"outline-container-org00a2e5b\" class=\"outline-2\"\u003e\n\u003ch2 id=\"org00a2e5b\"\u003eResults\u003c/h2\u003e\n\u003cdiv class=\"outline-text-2\" id=\"text-org00a2e5b\"\u003e\n\u003cp\u003e\nOur initial code took about \u003ccode\u003e0.66\u003c/code\u003e seconds to run in both spreadsheets.\n\u003c/p\u003e\n\n\u003cp\u003e\nInitial, unoptimized code.\n\u003c/p\u003e\n\u003cimg src=\"./resources/VBA_Unoptimized_2017.png\" alt=\"Unoptimized 2017\" width=\"500\"\u003e\n\u003cimg src=\"./resources/VBA_Unoptimized_2018.png\" alt=\"Unoptimized 2018\" width=\"500\"\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cp\u003e\nThe main problem with that version is that in had both conditional and nested loops that weren\u0026rsquo;t completely necessary.\n\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdiv id=\"outline-container-orga91b696\" class=\"outline-3\"\u003e\n\u003ch3 id=\"orga91b696\"\u003eOriginal Code\u003c/h3\u003e\n\u003cdiv class=\"outline-text-3\" id=\"text-orga91b696\"\u003e\n\u003cp\u003e\nThis is how our main loop looked initially.\n\u003c/p\u003e\n\u003cdiv class=\"org-src-container\"\u003e\n\u003cpre class=\"src src-java\"\u003e\u003cspan style=\"color: #33CCAA;\"\u003eFor\u003c/span\u003e \u003cspan style=\"color: #a9dbfa;\"\u003ei\u003c/span\u003e = \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e0\u003c/span\u003e To \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e11\u003c/span\u003e\n    ticker = tickers\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e\n    totalVolume = \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e0\u003c/span\u003e\n    Worksheets\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #c5937c;\"\u003e\"2018\"\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Activate\n    For j = \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e2\u003c/span\u003e To RowCount\n        If Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = ticker Then\n            totalVolume = totalVolume + Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e8\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value\n        End If\n        If Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej - \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.\u003cspan style=\"color: #33CCAA;\"\u003eValue\u003c/span\u003e \u003cspan style=\"color: #CC88CC;\"\u003e\u0026lt;\u0026gt;\u003c/span\u003e ticker And Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = ticker Then\n            startingPrice = Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e6\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value\n        End If\n        If Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej + \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.\u003cspan style=\"color: #33CCAA;\"\u003eValue\u003c/span\u003e \u003cspan style=\"color: #CC88CC;\"\u003e\u0026lt;\u0026gt;\u003c/span\u003e ticker And Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = ticker Then\n            endingPrice = Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ej, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e6\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value\n        End If\n    Next j\n    Worksheets\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #c5937c;\"\u003e\"All Stocks Analysis\"\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Activate\n    Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e4\u003c/span\u003e + i, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = ticker\n    Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e4\u003c/span\u003e + i, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e2\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = totalVolume\n    Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e4\u003c/span\u003e + i, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e3\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = endingPrice / startingPrice - \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\nNext i\n\u003c/pre\u003e\n\u003c/div\u003e\n\n\u003col class=\"org-ol\"\u003e\n\u003cli\u003eThe outer loop in this case is not necessary as we can initialize a different counter that is updated during the inner loop.\u003c/li\u003e\n\u003cli\u003eThere are too many single \u003ccode\u003eIf-Then\u003c/code\u003e conditionals, it is better to reduce them.\u003c/li\u003e\n\u003cli\u003eWe can move the outer loop to a separate process so we don\u0026rsquo;t have to call \u003ccode\u003eWorksheets(\"\").Activate\u003c/code\u003e every time.\u003c/li\u003e\n\u003cli\u003eHaving separate loops can improve readability and help us find bugs easily.\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cdiv id=\"outline-container-orgfaa14e9\" class=\"outline-3\"\u003e\n\u003ch3 id=\"orgfaa14e9\"\u003eRefactored Code\u003c/h3\u003e\n\u003cdiv class=\"outline-text-3\" id=\"text-orgfaa14e9\"\u003e\n\u003cp\u003e\nThis is how the main loop looks after refactoring it.\n\u003c/p\u003e\n\u003cdiv class=\"org-src-container\"\u003e\n\u003cpre class=\"src src-java\"\u003e\u003cspan style=\"color: #33CCAA;\"\u003eFor\u003c/span\u003e \u003cspan style=\"color: #a9dbfa;\"\u003ei\u003c/span\u003e = startIndex To RowCount\n    tickerVolumes\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003etickerIndex\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e = tickerVolumes\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003etickerIndex\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e + Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e8\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value\n    If Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.\u003cspan style=\"color: #33CCAA;\"\u003eValue\u003c/span\u003e \u003cspan style=\"color: #CC88CC;\"\u003e\u0026lt;\u0026gt;\u003c/span\u003e Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei - \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value Then\n        tickerStartingPrices\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003etickerIndex\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e = Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e6\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value\n    End If\n    If Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.\u003cspan style=\"color: #33CCAA;\"\u003eValue\u003c/span\u003e \u003cspan style=\"color: #CC88CC;\"\u003e\u0026lt;\u0026gt;\u003c/span\u003e Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei + \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value Then\n        tickerEndingPrices\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003etickerIndex\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e = Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e6\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value\n        tickerIndex = tickerIndex + \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\n    End If\nNext i\n\u003c/pre\u003e\n\u003c/div\u003e\n\n\u003cp\u003e\nOf course we moved half of the process to another loop, but this helps us a lot when reading it even without comments. Here is the second part of the process.\n\u003c/p\u003e\n\u003cdiv class=\"org-src-container\"\u003e\n\u003cpre class=\"src src-java\"\u003e\u003cspan style=\"color: #33CCAA;\"\u003eFor\u003c/span\u003e \u003cspan style=\"color: #a9dbfa;\"\u003ei\u003c/span\u003e = \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e0\u003c/span\u003e To \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e11\u003c/span\u003e\n    Worksheets\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #c5937c;\"\u003e\"All Stocks Analysis\"\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Activate\n    Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e4\u003c/span\u003e + i, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e2\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = tickerVolumes\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e\n    Cells\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003e\u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e4\u003c/span\u003e + i, \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e3\u003c/span\u003e\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e.Value = tickerEndingPrices\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e / tickerStartingPrices\u003cspan style=\"color: #CC88CC;\"\u003e(\u003c/span\u003ei\u003cspan style=\"color: #CC88CC;\"\u003e)\u003c/span\u003e - \u003cspan style=\"color: #BBCCAA; font-weight: bold;\"\u003e1\u003c/span\u003e\nNext i\n\u003c/pre\u003e\n\u003c/div\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003e\nFlat is better than nested. -Tim Peters.\n\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cdiv id=\"outline-container-org2024f32\" class=\"outline-3\"\u003e\n\u003ch3 id=\"org2024f32\"\u003eConclusions\u003c/h3\u003e\n\u003cdiv class=\"outline-text-3\" id=\"text-org2024f32\"\u003e\n\u003cp\u003e\nHere are the measurements after the code was refactored.\n\u003c/p\u003e\n\n\u003cimg src=\"./resources/VBA_Challenge_2017.png\" alt=\"optimized 2017\" width=\"500\"\u003e\n\u003cimg src=\"./resources/VBA_Challenge_2018.png\" alt=\"optimized 2018\" width=\"500\"\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003ctable border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\"\u003e\n\n\n\u003ccolgroup\u003e\n\u003ccol  class=\"org-right\" /\u003e\n\n\u003ccol  class=\"org-right\" /\u003e\n\n\u003ccol  class=\"org-right\" /\u003e\n\u003c/colgroup\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth scope=\"col\" class=\"org-right\"\u003eYear\u003c/th\u003e\n\u003cth scope=\"col\" class=\"org-right\"\u003eBefore\u003c/th\u003e\n\u003cth scope=\"col\" class=\"org-right\"\u003eAfter\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd class=\"org-right\"\u003e2017\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e0.65\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e0.12\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd class=\"org-right\"\u003e2018\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e0.66\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e0.14\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003cp\u003e\nWhich means that the code runs about \u003ccode\u003e5.5\u003c/code\u003e times faster. Imagine telling a client \u003ccode\u003e\"I'll get back to you in 1 business day\"\u003c/code\u003e against telling them \u003ccode\u003e\"I'll get back to you in a week\"\u003c/code\u003e. Of course that is a dramatic example but it matters.\n\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cdiv id=\"outline-container-org138b540\" class=\"outline-2\"\u003e\n\u003ch2 id=\"org138b540\"\u003eSummary\u003c/h2\u003e\n\u003cdiv class=\"outline-text-2\" id=\"text-org138b540\"\u003e\n\u003cp\u003e\nBeing able to refactor code means a few different things:\n\u003c/p\u003e\n\n\u003col class=\"org-ol\"\u003e\n\u003cli\u003eThe person refactoring the code may not be the same who wrote it, so comments and readability are important.\u003c/li\u003e\n\u003cli\u003eWe can get an initial result and solve a our problems at hand with a first version of the code but if we want to be able to solve more problems, we can always refactor to make it sure we can solve those problems too. As long as they remains within the code design.\u003c/li\u003e\n\u003cli\u003eWe can spend more time in data analysis instead of coding or waiting for results. If we manage to get good code and good performance, we will have one less thing to worry about.\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\n\u003cdiv id=\"outline-container-orga47a71c\" class=\"outline-3\"\u003e\n\u003ch3 id=\"orga47a71c\"\u003eCons of refactoring code:\u003c/h3\u003e\n\u003cdiv class=\"outline-text-3\" id=\"text-orga47a71c\"\u003e\n\u003col class=\"org-ol\"\u003e\n\u003cli\u003eIf the original design is too flawed we may spend we may spend too much time trying to figure out what the original coder intended, so we may be better off making our own script.\u003c/li\u003e\n\u003cli\u003eWe may find ourselves surrounded by a lot of special cases that the original script didn\u0026rsquo;t intent to cover and we may complicate things further if we start adding complexity to the design.\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cdiv id=\"outline-container-orga31af86\" class=\"outline-3\"\u003e\n\u003ch3 id=\"orga31af86\"\u003ePros of refactoring code:\u003c/h3\u003e\n\u003cdiv class=\"outline-text-3\" id=\"text-orga31af86\"\u003e\n\u003col class=\"org-ol\"\u003e\n\u003cli\u003eRefactoring can include using code from a completely different project but that fits the patterns of our problem at hand, so in that case is valid to reuse code and gain some time in the coding process.\u003c/li\u003e\n\u003cli\u003eAs long as the scripting language allows it, we can be sure that the code will last for many years as if something out of our control changes like a database or a functionality in Excel, we can refactor our code to fit that new requirement. In case of other languages, we can also include new libraries or technologies that will improve our code performance without needing to change the logic of it.\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\u003cdiv id=\"outline-container-orgb6b1278\" class=\"outline-2\"\u003e\n\u003ch2 id=\"orgb6b1278\"\u003eClosing Thoughts\u003c/h2\u003e\n\u003cdiv class=\"outline-text-2\" id=\"text-orgb6b1278\"\u003e\n\u003cp\u003e\nJust as completition of the data analysis, I include a short table of the partial results of the data. Ideally we could create more macros to keep adding years in a sequential way like this and it will only take a few seconds to keep organizing the data in ways we can get a much clearer picture of it.\n\u003c/p\u003e\n\n\u003ctable border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\"\u003e\n\n\n\u003ccolgroup\u003e\n\u003ccol  class=\"org-left\" /\u003e\n\n\u003ccol  class=\"org-right\" /\u003e\n\n\u003ccol  class=\"org-right\" /\u003e\n\n\u003ccol  class=\"org-right\" /\u003e\n\u003c/colgroup\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth scope=\"col\" class=\"org-left\"\u003eTicker\u003c/th\u003e\n\u003cth scope=\"col\" class=\"org-right\"\u003eReturn 2017\u003c/th\u003e\n\u003cth scope=\"col\" class=\"org-right\"\u003eReturn 2018\u003c/th\u003e\n\u003cth scope=\"col\" class=\"org-right\"\u003eChange\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd class=\"org-left\"\u003eAY\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e8.9%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-7.3%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-16.2%\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd class=\"org-left\"\u003eCSIQ\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e33.1%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-16.3%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-49.4%\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd class=\"org-left\"\u003eDQ\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e199.4%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-62.6%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-262.0%\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd class=\"org-left\"\u003eENPH\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e129.5%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e81.9%\u003c/td\u003e\n\u003ctd class=\"org-right\"\u003e-47.6%\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"postamble\" class=\"status\"\u003e\n\u003cp class=\"author\"\u003eAuthor: Alberto Valdez\u003c/p\u003e\n\u003cp class=\"date\"\u003eCreated: 2022-07-14 Thu 22:55\u003c/p\u003e\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertov5%2Ftec-data-02-vba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertov5%2Ftec-data-02-vba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertov5%2Ftec-data-02-vba/lists"}