{"id":52,"date":"2023-11-17T21:24:59","date_gmt":"2023-11-17T21:24:59","guid":{"rendered":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/"},"modified":"2023-12-06T11:34:04","modified_gmt":"2023-12-06T11:34:04","slug":"adicione-uma-nova-matriz-de-valores","status":"publish","type":"page","link":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/","title":{"rendered":"Como adicionar um novo valor a um array via vba?"},"content":{"rendered":"<div class=\"excel-before-content-2\" id=\"excel-2325811900\"><script type=\"text\/javascript\">\r\n\tatOptions = {\r\n\t\t'key' : 'c1158f160081d6540a8409e6925dab94',\r\n\t\t'format' : 'iframe',\r\n\t\t'height' : 250,\r\n\t\t'width' : 300,\r\n\t\t'params' : {}\r\n\t};\r\n<\/script>\r\n<script type=\"text\/javascript\" src=\"\/\/www.highperformanceformat.com\/c1158f160081d6540a8409e6925dab94\/invoke.js\"><\/script><\/div><div class=\"excel-before-content\" id=\"excel-3915890042\"><script type=\"text\/javascript\">\r\n\tatOptions = {\r\n\t\t'key' : 'c1158f160081d6540a8409e6925dab94',\r\n\t\t'format' : 'iframe',\r\n\t\t'height' : 250,\r\n\t\t'width' : 300,\r\n\t\t'params' : {}\r\n\t};\r\n<\/script>\r\n<script type=\"text\/javascript\" src=\"\/\/www.highperformanceformat.com\/c1158f160081d6540a8409e6925dab94\/invoke.js\"><\/script><\/div> <p>Para adicionar um novo valor a um array existente, voc\u00ea deve ter um array din\u00e2mico para redefinir seus elementos e, ao fazer isso, deve reter os valores dos elementos antigos. Isso ajuda a adicionar apenas o valor ao novo elemento definido e deixa o restante da pe\u00e7a intacto.<\/p><p> Abaixo voc\u00ea tem um array no qual definiu dois elementos. Como este \u00e9 um array din\u00e2mico, voc\u00ea tem uma instru\u00e7\u00e3o \u201cReDim\u201d para definir dois elementos e ent\u00e3o adicionar valores a esses elementos. <\/p><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-57215\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png\" sizes=\"auto, \" srcset=\"\" alt=\"matriz din\u00e2mica para redefinir elementos\" width=\"497\" height=\"359\"><\/figure><\/div><p> Em seguida, adicionaremos um terceiro elemento a este array.<\/p><h2 class=\"wp-block-heading\"> <strong>Adicione um novo valor a um array em VBA<\/strong><\/h2><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-57216\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/2-ajouter-une-nouvelle-valeur-a-un-tableau-2.png\" sizes=\"auto, \" srcset=\"\" alt=\"\" width=\"505\" height=\"564\"><\/figure><\/div><ol type=\"1\"><li> Primeiro, voc\u00ea precisa usar a instru\u00e7\u00e3o \u201cReDim\u201d com a palavra-chave \u201cPreserve\u201d para preservar ambos os elementos, incluindo o novo elemento ao qual deseja adicionar o valor.<\/li><li> Em seguida, voc\u00ea precisa definir os elementos que deseja ter no array. Aqui voc\u00ea precisa ter tr\u00eas elementos, ent\u00e3o usamos de 1 a 3 para isso.<\/li><li> Depois disso, voc\u00ea precisa agregar valor ao terceiro elemento, que \u00e9 o novo elemento que voc\u00ea define.<\/li><li> No final use o <a href=\"https:\/\/exceladvisor.org\/pt\/impressao-de-depuracao-de-janela-imediata\/\">debug.print<\/a> para obter todos os itens com os novos itens na janela imediata.<\/li><\/ol><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Option Explicit Option Base 1 Sub vba_array_add_value() Dim myArray() As Variant ReDim myArray(2) myArray(1) = 5 myArray(2) = 10 ReDim Preserve myArray(1 To 3) myArray(3) = 15 Debug.Print myArray(1) Debug.Print myArray(2) Debug.Print myArray(3) End Sub<\/code><\/pre><p> Deixe-me compartilhar mais algumas palavras com voc\u00ea.<\/p><ul><li> Voc\u00ea deve declarar um array como um array din\u00e2mico no in\u00edcio se souber que precisar\u00e1 adicionar mais valor ao array no c\u00f3digo posteriormente.<\/li><li> Usando este m\u00e9todo voc\u00ea s\u00f3 pode adicionar um novo elemento no final do array.<\/li><\/ul><div class=\"gb-container gb-container-4db6181c gb-container-mt\"> <a class=\"gb-button gb-button-c5897111 gb-button-text gb-button-mt-button\" href=\"https:\/\/exceladvisor.org\/pt\/vba\/\">O que \u00e9 VBA<\/a><h2 class=\"gb-headline gb-headline-665e5f6b gb-headline-text gb-headline-mt-heading\"> Saiba mais sobre <a href=\"https:\/\/exceladvisor.org\/pt\/pinturas\/\">tabelas VBA<\/a> <\/h2><div class=\"gb-grid-wrapper gb-grid-wrapper-a20baf7c gb-grid-wrapper-mt-grid\"><div class=\"gb-grid-column gb-grid-column-65ddf67e\"><div class=\"gb-container gb-container-65ddf67e\"><ul><li> <a href=\"https:\/\/exceladvisor.org\/pt\/tamanho-da-matriz\/\">Comprimento da matriz VBA (tamanho)<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/pt\/mesa-com-correntes\/\">Matriz VBA com strings<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/pt\/apague-o-quadro\/\">Matriz limpa VBA<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/pt\/tabela-dinamica\/\">Tabela din\u00e2mica VBA<\/a> <\/li><\/ul><\/div><\/div><div class=\"gb-grid-column gb-grid-column-50067b57\"><div class=\"gb-container gb-container-50067b57\"><ul><li> <a href=\"https:\/\/exceladvisor.org\/pt\/matriz-de-loop-vba\/\">Loop VBA em uma matriz<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/pt\/matriz-multidimensional\/\">Matriz multidimensional VBA<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/pt\/praia-tem-uma-pintura\/\">Intervalo VBA para um array<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/pt\/tabela-de-classificacao\/\">Tabela de sa\u00edda VBA<\/a><\/li><\/ul><\/div><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"ub_ctt_via":"","footnotes":""},"class_list":["post-52","page","type-page","status-publish","hentry"],"featured_image_src":null,"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como adicionar um novo valor a um array via VBA?<\/title>\n<meta name=\"description\" content=\"Neste tutorial, voc\u00ea aprender\u00e1 como adicionar um novo valor a um array em VBA. Adicione o valor ao novo item que voc\u00ea possui\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como adicionar um novo valor a um array via VBA?\" \/>\n<meta property=\"og:description\" content=\"Neste tutorial, voc\u00ea aprender\u00e1 como adicionar um novo valor a um array em VBA. Adicione o valor ao novo item que voc\u00ea possui\" \/>\n<meta property=\"og:url\" content=\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/\" \/>\n<meta property=\"og:site_name\" content=\"Excel Advisor\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-06T11:34:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/\",\"url\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/\",\"name\":\"Como adicionar um novo valor a um array via VBA?\",\"isPartOf\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png\",\"datePublished\":\"2023-11-17T21:24:59+00:00\",\"dateModified\":\"2023-12-06T11:34:04+00:00\",\"description\":\"Neste tutorial, voc\u00ea aprender\u00e1 como adicionar um novo valor a um array em VBA. Adicione o valor ao novo item que voc\u00ea possui\",\"breadcrumb\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#primaryimage\",\"url\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png\",\"contentUrl\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/exceladvisor.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como adicionar um novo valor a um array via vba?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/#website\",\"url\":\"https:\/\/exceladvisor.org\/pt\/\",\"name\":\"Excel Advisor\",\"description\":\"O seu guia definitivo para dominar os dados!\",\"publisher\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/exceladvisor.org\/pt\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/#organization\",\"name\":\"Excel Advisor\",\"url\":\"https:\/\/exceladvisor.org\/pt\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/exceladvisor.org\/pt\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png\",\"contentUrl\":\"https:\/\/exceladvisor.org\/pt\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png\",\"width\":105,\"height\":36,\"caption\":\"Excel Advisor\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como adicionar um novo valor a um array via VBA?","description":"Neste tutorial, voc\u00ea aprender\u00e1 como adicionar um novo valor a um array em VBA. Adicione o valor ao novo item que voc\u00ea possui","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:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/","og_locale":"pt_PT","og_type":"article","og_title":"Como adicionar um novo valor a um array via VBA?","og_description":"Neste tutorial, voc\u00ea aprender\u00e1 como adicionar um novo valor a um array em VBA. Adicione o valor ao novo item que voc\u00ea possui","og_url":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/","og_site_name":"Excel Advisor","article_modified_time":"2023-12-06T11:34:04+00:00","og_image":[{"url":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/","url":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/","name":"Como adicionar um novo valor a um array via VBA?","isPartOf":{"@id":"https:\/\/exceladvisor.org\/pt\/#website"},"primaryImageOfPage":{"@id":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#primaryimage"},"image":{"@id":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#primaryimage"},"thumbnailUrl":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png","datePublished":"2023-11-17T21:24:59+00:00","dateModified":"2023-12-06T11:34:04+00:00","description":"Neste tutorial, voc\u00ea aprender\u00e1 como adicionar um novo valor a um array em VBA. Adicione o valor ao novo item que voc\u00ea possui","breadcrumb":{"@id":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/"]}]},{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#primaryimage","url":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png","contentUrl":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-tableau-dynamique-pour-redefinir-les-elements-1-2.png"},{"@type":"BreadcrumbList","@id":"https:\/\/exceladvisor.org\/pt\/adicione-uma-nova-matriz-de-valores\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/exceladvisor.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como adicionar um novo valor a um array via vba?"}]},{"@type":"WebSite","@id":"https:\/\/exceladvisor.org\/pt\/#website","url":"https:\/\/exceladvisor.org\/pt\/","name":"Excel Advisor","description":"O seu guia definitivo para dominar os dados!","publisher":{"@id":"https:\/\/exceladvisor.org\/pt\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/exceladvisor.org\/pt\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-PT"},{"@type":"Organization","@id":"https:\/\/exceladvisor.org\/pt\/#organization","name":"Excel Advisor","url":"https:\/\/exceladvisor.org\/pt\/","logo":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/exceladvisor.org\/pt\/#\/schema\/logo\/image\/","url":"https:\/\/exceladvisor.org\/pt\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png","contentUrl":"https:\/\/exceladvisor.org\/pt\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png","width":105,"height":36,"caption":"Excel Advisor"},"image":{"@id":"https:\/\/exceladvisor.org\/pt\/#\/schema\/logo\/image\/"}}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/pages\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":1,"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/pages\/52\/revisions"}],"predecessor-version":[{"id":795,"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/pages\/52\/revisions\/795"}],"wp:attachment":[{"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/media?parent=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}