{"id":2049,"date":"2023-10-22T19:48:52","date_gmt":"2023-10-22T19:48:52","guid":{"rendered":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/"},"modified":"2023-12-10T06:26:07","modified_gmt":"2023-12-10T06:26:07","slug":"tabella-dei-valori-di-ricerca","status":"publish","type":"page","link":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/","title":{"rendered":"Come trovare un valore in un array usando vba?"},"content":{"rendered":"<div class=\"excel-prima-del-contenuto\" id=\"excel-2192433527\"><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>Quando memorizzi valori in un array, potrebbero esserci momenti in cui \u00e8 necessario eseguire una ricerca nell&#8217;array. In questo caso, \u00e8 necessario conoscere i metodi che \u00e8 possibile utilizzare. Ora guarda il codice seguente che pu\u00f2 aiutarti a capire come cercare un valore in un 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=\"trova-un-valore-in-un-array-1\" width=\"709\" height=\"1456\"><\/figure><\/div><ol type=\"1\"><li> Nella prima parte del codice hai <a href=\"https:\/\/exceladvisor.org\/it\/variabili\/\">delle variabili<\/a> che dovrai utilizzare pi\u00f9 avanti nel codice.<\/li><li> Successivamente, la parte successiva <a href=\"https:\/\/exceladvisor.org\/it\/numero-casuale\/\">genera numeri casuali<\/a> utilizzando <a href=\"https:\/\/exceladvisor.org\/it\/rnd\/\">RND<\/a> per ottenere i dieci valori dall&#8217;array.<\/li><li> Successivamente, una casella di input ti consente di inserire il valore che desideri cercare nella tabella.<\/li><li> Successivamente, hai una riga che utilizza l&#8217; <a href=\"https:\/\/exceladvisor.org\/it\/se-2\/\">istruzione IF<\/a> per verificare se il valore inserito nella casella di input \u00e8 un numero o meno.<\/li><li> In questa parte hai un codice per la stringa da utilizzare nella <a href=\"https:\/\/exceladvisor.org\/it\/casella-msg-vba\/\">finestra di messaggio<\/a> se il valore inserito non viene trovato.<\/li><li> Questa parte del codice utilizza un <a href=\"https:\/\/exceladvisor.org\/it\/per-il-ciclo\/\">ciclo For (For Each)<\/a> per <a href=\"https:\/\/exceladvisor.org\/it\/dimensione-della-matrice\/\">scorrere ogni elemento nell&#8217;array<\/a> e verificare se il valore immesso \u00e8 nell&#8217;array o meno.<\/li><li> L&#8217;ultima parte del codice visualizza un messaggio che indica se il valore \u00e8 stato trovato o meno.<\/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\/it\/vba\/\">Cos&#8217;\u00e8 VBA<\/a><h2 class=\"gb-headline gb-headline-665e5f6b gb-headline-text gb-headline-mt-heading\"> Ulteriori informazioni sulle <a href=\"https:\/\/exceladvisor.org\/it\/dipinti\/\">tabelle 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\/it\/aggiungere-una-nuova-matrice-di-valori\/\">VBA Aggiungi un nuovo valore all&#8217;array<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/it\/dimensione-della-matrice\/\">Lunghezza dell&#8217;array VBA (dimensione)<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/it\/tavolo-con-catene\/\">Array VBA con stringhe<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/it\/cancella-la-lavagna\/\">Cancella matrice VBA<\/a><\/li><li> <a href=\"https:\/\/exceladvisor.org\/it\/tabella-dinamica\/\">Tabella dinamica 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-2049","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>Come trovare un valore in un array usando VBA?<\/title>\n<meta name=\"description\" content=\"In questo tutorial imparerai come cercare un array utilizzando un 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\/it\/tabella-dei-valori-di-ricerca\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come trovare un valore in un array usando VBA?\" \/>\n<meta property=\"og:description\" content=\"In questo tutorial imparerai come cercare un array utilizzando un loop.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/\" \/>\n<meta property=\"og:site_name\" content=\"Excel Advisor\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-10T06:26:07+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 di lettura stimato\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/\",\"url\":\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/\",\"name\":\"Come trovare un valore in un array usando VBA?\",\"isPartOf\":{\"@id\":\"https:\/\/exceladvisor.org\/it\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#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-10T06:26:07+00:00\",\"description\":\"In questo tutorial imparerai come cercare un array utilizzando un loop.\",\"breadcrumb\":{\"@id\":\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#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\/it\/tabella-dei-valori-di-ricerca\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/exceladvisor.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come trovare un valore in un array usando vba?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/exceladvisor.org\/it\/#website\",\"url\":\"https:\/\/exceladvisor.org\/it\/\",\"name\":\"Excel Advisor\",\"description\":\"Tips, Tricks, and Time-Saving Hacks\",\"publisher\":{\"@id\":\"https:\/\/exceladvisor.org\/it\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/exceladvisor.org\/it\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/exceladvisor.org\/it\/#organization\",\"name\":\"Excel Advisor\",\"url\":\"https:\/\/exceladvisor.org\/it\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/exceladvisor.org\/it\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/exceladvisor.org\/it\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png\",\"contentUrl\":\"https:\/\/exceladvisor.org\/it\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png\",\"width\":105,\"height\":36,\"caption\":\"Excel Advisor\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/it\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come trovare un valore in un array usando VBA?","description":"In questo tutorial imparerai come cercare un array utilizzando un 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\/it\/tabella-dei-valori-di-ricerca\/","og_locale":"it_IT","og_type":"article","og_title":"Come trovare un valore in un array usando VBA?","og_description":"In questo tutorial imparerai come cercare un array utilizzando un loop.","og_url":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/","og_site_name":"Excel Advisor","article_modified_time":"2023-12-10T06:26:07+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 di lettura stimato":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/","url":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/","name":"Come trovare un valore in un array usando VBA?","isPartOf":{"@id":"https:\/\/exceladvisor.org\/it\/#website"},"primaryImageOfPage":{"@id":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#primaryimage"},"image":{"@id":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#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-10T06:26:07+00:00","description":"In questo tutorial imparerai come cercare un array utilizzando un loop.","breadcrumb":{"@id":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/exceladvisor.org\/it\/tabella-dei-valori-di-ricerca\/#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\/it\/tabella-dei-valori-di-ricerca\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/exceladvisor.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come trovare un valore in un array usando vba?"}]},{"@type":"WebSite","@id":"https:\/\/exceladvisor.org\/it\/#website","url":"https:\/\/exceladvisor.org\/it\/","name":"Excel Advisor","description":"Tips, Tricks, and Time-Saving Hacks","publisher":{"@id":"https:\/\/exceladvisor.org\/it\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/exceladvisor.org\/it\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Organization","@id":"https:\/\/exceladvisor.org\/it\/#organization","name":"Excel Advisor","url":"https:\/\/exceladvisor.org\/it\/","logo":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/exceladvisor.org\/it\/#\/schema\/logo\/image\/","url":"https:\/\/exceladvisor.org\/it\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png","contentUrl":"https:\/\/exceladvisor.org\/it\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png","width":105,"height":36,"caption":"Excel Advisor"},"image":{"@id":"https:\/\/exceladvisor.org\/it\/#\/schema\/logo\/image\/"}}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/pages\/2049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/comments?post=2049"}],"version-history":[{"count":1,"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/pages\/2049\/revisions"}],"predecessor-version":[{"id":2754,"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/pages\/2049\/revisions\/2754"}],"wp:attachment":[{"href":"https:\/\/exceladvisor.org\/it\/wp-json\/wp\/v2\/media?parent=2049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}