{"id":13014,"date":"2022-10-02T18:46:41","date_gmt":"2022-10-02T13:16:41","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/"},"modified":"2022-10-02T18:46:41","modified_gmt":"2022-10-02T13:16:41","slug":"solved-vba-arrays-from-google-apps-script","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/","title":{"rendered":"[Solved] vba arrays from google apps script"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-43926779\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"43926779\" data-parentid=\"43924048\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Google Apps script is based on javascript. VBA is based on Visual Basic. Hardcoding it is a possibility but you end up with some  funky array and you&#8217;re then limited to VBA&#8217;s clunky array methods (or lack thereof).<\/p>\n<pre><code>Function createChargeList()\n    Dim var(5)\n    var(0) = [{\"No.\", \"Name\", \"Cooldown\", \"Power\", \"Energy Loss\", \"Type\", \"Damage Window Start\"}]\n    var(1) = [{1.0, \"AerialAce\", 240.0, 55.0, 33.0, 3.0, 190.0}]\n    var(2) = [{2.0, \"AirCutter\", 270.0, 60.0, 50.0, 3.0, 180.0}]\n    var(3) = [{3.0, \"AncientPower\", 350.0, 70.0, 33.0, 6.0, 285.0}]\n    var(4) = [{4.0, \"AquaJet\", 260.0, 45.0, 33.0, 11.0, 170.0}]\n    var(5) = [{5.0, \"AquaTail\", 190.0, 50.0, 33.0, 11.0, 120.0}]\n    createChargeList = var\n    \nEnd Function\n<\/code><\/pre>\n<p>Or you could &#8220;hardcode&#8221; it to a <code>Dictionary<\/code> or <code>Collection<\/code> or an <code>ArrayList<\/code> (of <code>ArrayList<\/code>s). There would be some benefits to using a Dict or ArrayList because they have other methods you can use. Dictionary example, this is not how I would structure it but it shows how you could do it:<\/p>\n<pre><code>Function createChargeDict()\n    Dim d As Object\n    Set d = CreateObject(\"Scripting.Dictionary\")\n    d(\"No.\") = Array(1#, 2#, 3#, 4#, 5#)\n    d(\"Name\") = Split(\"AerialAce,AirCutter,AncientPower,AquaJet,AquaTail\", \",\")\n    'etc...\n    Set createChargeDict = d\nEnd Function\n<\/code><\/pre>\n<p>But, it&#8217;s going to be difficult to &#8220;hardcode&#8221; it if it&#8217;s more than a very small amount of data e.g., per Tim&#8217;s answer (or likewise through what I did, above), and of course if anything <em>changes<\/em> you need to go and edit the code.<\/p>\n<p>Another option would be to save the data as a CSV or otherwise delimited file and read it in to an array\/dict\/list\/collection at runtime.<\/p>\n<h1>What I would do (Opinion)<\/h1>\n<p>Another more common approach &#8212; as you inquired about in your comments &#8212; would be to simply create a table on a worksheet (optionally: hide the worksheet so user&#8217;s can&#8217;t mess it up), assign a <code>Name<\/code> to represent the table&#8217;s range, and then you can just refer to the range&#8217;s <code>.Value<\/code> property which will return an array.<\/p>\n<p>The added benefits of this is that you can use all of the <code>Worksheet<\/code> methods and functions against the range of cells (or as a Table\/<code>ListObject<\/code> on a sheet), and then you can do a lot more with it in terms of filtering, slicing, finding elements, matching\/indexing, etc., and it&#8217;s also easier to update.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved vba arrays from google apps script <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Google Apps script is based on javascript. VBA is based on Visual Basic. Hardcoding it is a possibility but you end up with some funky array and you&#8217;re then limited to VBA&#8217;s clunky array methods (or lack thereof). Function createChargeList() Dim var(5) var(0) = [{&#8220;No.&#8221;, &#8220;Name&#8221;, &#8220;Cooldown&#8221;, &#8220;Power&#8221;, &#8220;Energy Loss&#8221;, &#8220;Type&#8221;, &#8220;Damage Window Start&#8221;}] &#8230; <a title=\"[Solved] vba arrays from google apps script\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\" aria-label=\"More on [Solved] vba arrays from google apps script\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[400,951,401],"class_list":["post-13014","post","type-post","status-publish","format-standard","hentry","category-solved","tag-excel","tag-google-apps-script","tag-vba"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] vba arrays from google apps script - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] vba arrays from google apps script - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Google Apps script is based on javascript. VBA is based on Visual Basic. Hardcoding it is a possibility but you end up with some funky array and you&#8217;re then limited to VBA&#8217;s clunky array methods (or lack thereof). Function createChargeList() Dim var(5) var(0) = [{&quot;No.&quot;, &quot;Name&quot;, &quot;Cooldown&quot;, &quot;Power&quot;, &quot;Energy Loss&quot;, &quot;Type&quot;, &quot;Damage Window Start&quot;}] ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-02T13:16:41+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] vba arrays from google apps script\",\"datePublished\":\"2022-10-02T13:16:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\"},\"wordCount\":299,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"excel\",\"google-apps-script\",\"vba\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\",\"name\":\"[Solved] vba arrays from google apps script - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-02T13:16:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] vba arrays from google apps script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] vba arrays from google apps script - JassWeb","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:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] vba arrays from google apps script - JassWeb","og_description":"[ad_1] Google Apps script is based on javascript. VBA is based on Visual Basic. Hardcoding it is a possibility but you end up with some funky array and you&#8217;re then limited to VBA&#8217;s clunky array methods (or lack thereof). Function createChargeList() Dim var(5) var(0) = [{\"No.\", \"Name\", \"Cooldown\", \"Power\", \"Energy Loss\", \"Type\", \"Damage Window Start\"}] ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/","og_site_name":"JassWeb","article_published_time":"2022-10-02T13:16:41+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] vba arrays from google apps script","datePublished":"2022-10-02T13:16:41+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/"},"wordCount":299,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["excel","google-apps-script","vba"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/","url":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/","name":"[Solved] vba arrays from google apps script - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-02T13:16:41+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-vba-arrays-from-google-apps-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] vba arrays from google apps script"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/13014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=13014"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/13014\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=13014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=13014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=13014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}