{"id":576,"date":"2023-10-22T19:48:52","date_gmt":"2023-10-22T19:48:52","guid":{"rendered":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/"},"modified":"2023-12-06T11:37:34","modified_gmt":"2023-12-06T11:37:34","slug":"tabela-de-valores-de-pesquisa","status":"publish","type":"page","link":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/","title":{"rendered":"Como encontrar um valor em um array usando vba?"},"content":{"rendered":"<div class=\"excel-before-content-2\" id=\"excel-1296557262\"><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-2006510752\"><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>Ao armazenar valores em um array, pode haver momentos em que voc\u00ea precise fazer uma pesquisa no array. Nesse caso, voc\u00ea precisa conhecer os m\u00e9todos que pode usar. Agora observe o c\u00f3digo abaixo, que pode ajud\u00e1-lo a entender como pesquisar um valor em um array. <\/p><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-57290\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png\" sizes=\"auto, \" srcset=\"\" alt=\"encontre um valor em uma matriz-1\" width=\"709\" height=\"1456\"><\/figure><\/div><ol type=\"1\"><li> Na primeira parte do c\u00f3digo voc\u00ea tem <a href=\"https:\/\/exceladvisor.org\/pt\/variaveis\/\">vari\u00e1veis<\/a> que voc\u00ea precisa usar posteriormente no c\u00f3digo.<\/li><li> Depois disso, a pr\u00f3xima parte <a href=\"https:\/\/exceladvisor.org\/pt\/numero-aleatorio\/\">gera n\u00fameros aleat\u00f3rios<\/a> usando <a href=\"https:\/\/exceladvisor.org\/pt\/segundo\/\">RND<\/a> para obter os dez valores do array.<\/li><li> A seguir, uma caixa de entrada permite inserir o valor que deseja pesquisar na tabela.<\/li><li> Depois disso, voc\u00ea tem uma linha que usa a <a href=\"https:\/\/exceladvisor.org\/pt\/se-2\/\">instru\u00e7\u00e3o IF<\/a> para verificar se o valor inserido na caixa de entrada \u00e9 um n\u00famero ou n\u00e3o.<\/li><li> Nesta parte voc\u00ea tem um c\u00f3digo para a string usar na <a href=\"https:\/\/exceladvisor.org\/pt\/caixa-de-mensagens-vba\/\">caixa de mensagem<\/a> caso o valor que voc\u00ea digitou n\u00e3o for encontrado.<\/li><li> Esta parte do c\u00f3digo usa um <a href=\"https:\/\/exceladvisor.org\/pt\/para-o-circuito\/\">loop For (For Each)<\/a> para <a href=\"https:\/\/exceladvisor.org\/pt\/tamanho-da-matriz\/\">percorrer cada elemento da matriz<\/a> e verificar se o valor inserido est\u00e1 na matriz ou n\u00e3o.<\/li><li> A \u00faltima parte do c\u00f3digo exibe uma mensagem indicando se o valor foi encontrado ou n\u00e3o.<\/li><\/ol><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Option Base 1 Sub vba_array_search() 'this section declares an array and variables 'that you need to search within the array. Dim myArray(10) As Integer Dim i As Integer Dim varUserNumber As Variant Dim strMsg As String 'This part of the code adds 10 random numbers to 'the array and shows the result in the 'immediate window as well. For i = 1 To 10 myArray(i) = Int(Rnd * 10) Debug.Print myArray(i) Next i 'it is an input box that asks 'you the number that you want to find Loopback: varUserNumber = InputBox _ (\"Enter a number between 1 and 10 to search for:\", _ \"Linear Search Demonstrator\") 'it's an if statement that checks for the value that you 'have entered in the input box. If varUserNumber = \"\" Then End If Not IsNumeric(varUserNumber) Then GoTo Loopback If varUserNumber &lt; 1 Or varUserNumber &gt; 10 Then GoTo Loopback 'message to show if the value doesn't found. strMsg = \"Your value, \" &amp; varUserNumber &amp; _ \", was not found in the array.\" 'loop through the array and match each value with the 'the value you have entered in the input box. For i = 1 To UBound(myArray) If myArray(i) = varUserNumber Then strMsg = \"Your value, \" &amp; varUserNumber &amp; _ \", was found at position \" &amp; i &amp; \" in the array.\" Exit For End If Next i 'message box in the end MsgBox _ strMsg, vbOKOnly + vbInformation, _ \"Linear Search Result\" End Sub<\/code><\/pre><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\/adicione-uma-nova-matriz-de-valores\/\">VBA Adicionar novo valor ao array<\/a><\/li><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><\/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-576","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 encontrar um valor em um array usando VBA?<\/title>\n<meta name=\"description\" content=\"Neste tutorial, voc\u00ea aprende como pesquisar um array usando um loop.\" \/>\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\/tabela-de-valores-de-pesquisa\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como encontrar um valor em um array usando VBA?\" \/>\n<meta property=\"og:description\" content=\"Neste tutorial, voc\u00ea aprende como pesquisar um array usando um loop.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/\" \/>\n<meta property=\"og:site_name\" content=\"Excel Advisor\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-06T11:37:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.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\/tabela-de-valores-de-pesquisa\/\",\"url\":\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/\",\"name\":\"Como encontrar um valor em um array usando VBA?\",\"isPartOf\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png\",\"datePublished\":\"2023-10-22T19:48:52+00:00\",\"dateModified\":\"2023-12-06T11:37:34+00:00\",\"description\":\"Neste tutorial, voc\u00ea aprende como pesquisar um array usando um loop.\",\"breadcrumb\":{\"@id\":\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#primaryimage\",\"url\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png\",\"contentUrl\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/exceladvisor.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como encontrar um valor em um array usando 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 encontrar um valor em um array usando VBA?","description":"Neste tutorial, voc\u00ea aprende como pesquisar um array usando um loop.","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\/tabela-de-valores-de-pesquisa\/","og_locale":"pt_PT","og_type":"article","og_title":"Como encontrar um valor em um array usando VBA?","og_description":"Neste tutorial, voc\u00ea aprende como pesquisar um array usando um loop.","og_url":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/","og_site_name":"Excel Advisor","article_modified_time":"2023-12-06T11:37:34+00:00","og_image":[{"url":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.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\/tabela-de-valores-de-pesquisa\/","url":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/","name":"Como encontrar um valor em um array usando VBA?","isPartOf":{"@id":"https:\/\/exceladvisor.org\/pt\/#website"},"primaryImageOfPage":{"@id":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#primaryimage"},"image":{"@id":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#primaryimage"},"thumbnailUrl":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png","datePublished":"2023-10-22T19:48:52+00:00","dateModified":"2023-12-06T11:37:34+00:00","description":"Neste tutorial, voc\u00ea aprende como pesquisar um array usando um loop.","breadcrumb":{"@id":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/"]}]},{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#primaryimage","url":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png","contentUrl":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/1-rechercher-une-valeur-dans-un-tableau-1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/exceladvisor.org\/pt\/tabela-de-valores-de-pesquisa\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/exceladvisor.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como encontrar um valor em um array usando 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\/576","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=576"}],"version-history":[{"count":1,"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/pages\/576\/revisions"}],"predecessor-version":[{"id":1050,"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/pages\/576\/revisions\/1050"}],"wp:attachment":[{"href":"https:\/\/exceladvisor.org\/pt\/wp-json\/wp\/v2\/media?parent=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}