{"id":4470,"date":"2023-07-10T21:20:46","date_gmt":"2023-07-10T21:20:46","guid":{"rendered":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/"},"modified":"2023-07-10T21:20:46","modified_gmt":"2023-07-10T21:20:46","slug":"vba-confronta-le-stringhe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/","title":{"rendered":"Come confrontare le stringhe in vba: con esempi"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi in VBA per confrontare le stringhe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: confronto tra stringhe con distinzione tra maiuscole e minuscole<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #0000ff;\">SubCompareStrings<\/span> ()\n    <span style=\"color: #0000ff;\">Dim<\/span> i <span style=\"color: #0000ff;\">As<\/span> Integer\n\n    <span style=\"color: #0000ff;\">For<\/span> i = 2 <span style=\"color: #0000ff;\">To<\/span> 10\n        Range(\" <span style=\"color: #ff0000;\">C<\/span> \" &amp; i) = StrComp(Range(\" <span style=\"color: #ff0000;\">A<\/span> \" &amp; i), Range(\" <span style=\"color: #ff0000;\">B<\/span> \" &amp; i)) = 0\n    <span style=\"color: #0000ff;\">Next<\/span> i\n<span style=\"color: #0000ff;\">End Sub\n<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Questa macro eseguir\u00e0 un confronto tra stringhe con distinzione tra maiuscole e minuscole tra le stringhe nelle celle corrispondenti negli intervalli <strong>A2:A10<\/strong> e <strong>B2:B10<\/strong> e restituir\u00e0 VERO o FALSO nell&#8217;intervallo <strong>C2:C10<\/strong> per indicare se le stringhe sono uguali o meno.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: confronto tra stringhe senza distinzione tra maiuscole e minuscole<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #0000ff;\">SubCompareStrings<\/span> ()\n    <span style=\"color: #0000ff;\">Dim<\/span> i <span style=\"color: #0000ff;\">As<\/span> Integer\n\n    <span style=\"color: #0000ff;\">For<\/span> i = 2 <span style=\"color: #0000ff;\">To<\/span> 10\n        Range(\" <span style=\"color: #ff0000;\">C<\/span> \" &amp; i) = StrComp(Range(\" <span style=\"color: #ff0000;\">A<\/span> \" &amp; i), Range(\" <span style=\"color: #ff0000;\">B<\/span> \" &amp; i), vbTextCompare) = 0\n    <span style=\"color: #0000ff;\">Next<\/span> i\n<span style=\"color: #0000ff;\">End Sub<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Questa macro eseguir\u00e0 un confronto tra stringhe senza distinzione tra maiuscole e minuscole tra le stringhe nelle celle corrispondenti negli intervalli <strong>A2:A10<\/strong> e <strong>B2:B10<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare nella pratica ciascun metodo con i seguenti elenchi di stringhe in Excel:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-34969 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/str1.png\" alt=\"\" width=\"476\" height=\"444\" srcset=\"\" sizes=\"\"><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: confronto di stringhe con distinzione tra maiuscole e minuscole in VBA<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo creare la seguente macro per eseguire un confronto di stringhe con distinzione tra maiuscole e minuscole tra ciascuna stringa corrispondente nelle colonne A e B:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #0000ff;\">SubCompareStrings<\/span> ()\n    <span style=\"color: #0000ff;\">Dim<\/span> i <span style=\"color: #0000ff;\">As<\/span> Integer\n\n    <span style=\"color: #0000ff;\">For<\/span> i = 2 <span style=\"color: #0000ff;\">To<\/span> 10\n        Range(\" <span style=\"color: #ff0000;\">C<\/span> \" &amp; i) = StrComp(Range(\" <span style=\"color: #ff0000;\">A<\/span> \" &amp; i), Range(\" <span style=\"color: #ff0000;\">B<\/span> \" &amp; i)) = 0\n    <span style=\"color: #0000ff;\">Next<\/span> i\n<span style=\"color: #0000ff;\">End Sub<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Quando eseguiamo questa macro, riceviamo il seguente output:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-34970\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/str2.png\" alt=\"confronto delle stringhe con distinzione tra maiuscole e minuscole in VBA\" width=\"477\" height=\"401\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">La colonna C restituisce <strong>TRUE<\/strong> se le stringhe sono uguali e hanno lo stesso caso.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Altrimenti, la colonna C restituisce <strong>FALSE<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: confronto di stringhe senza distinzione tra maiuscole e minuscole in VBA<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo creare la seguente macro per eseguire un confronto di stringhe senza distinzione tra maiuscole e minuscole tra ciascuna stringa corrispondente nelle colonne A e B:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #0000ff;\">SubCompareStrings<\/span> ()\n    <span style=\"color: #0000ff;\">Dim<\/span> i <span style=\"color: #0000ff;\">As<\/span> Integer\n\n    <span style=\"color: #0000ff;\">For<\/span> i = 2 <span style=\"color: #0000ff;\">To<\/span> 10\n        Range(\" <span style=\"color: #ff0000;\">C<\/span> \" &amp; i) = StrComp(Range(\" <span style=\"color: #ff0000;\">A<\/span> \" &amp; i), Range(\" <span style=\"color: #ff0000;\">B<\/span> \" &amp; i), vbTextCompare) = 0\n    <span style=\"color: #0000ff;\">Next<\/span> i\n<span style=\"color: #0000ff;\">End Sub<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Quando eseguiamo questa macro, riceviamo il seguente output:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-34971\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/str3.png\" alt=\"confronto di stringhe senza distinzione tra maiuscole e minuscole in VBA\" width=\"499\" height=\"448\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">La colonna C restituisce <strong>TRUE<\/strong> se le stringhe sono uguali, indipendentemente dal caso.<\/span><\/p>\n<p> <span style=\"color: #000000;\">La colonna C restituisce <strong>FALSE<\/strong> solo se le stringhe non sono uguali.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : <a href=\"https:\/\/learn.microsoft.com\/en-us\/office\/vba\/language\/reference\/user-interface-help\/strcomp-function\" target=\"_blank\" rel=\"noopener\">qui<\/a> \u00e8 possibile trovare la documentazione completa della funzione <strong>StrComp<\/strong> in VBA.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in VBA:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/vba-sostituisce-il-carattere-nella-stringa\/\" target=\"_blank\" rel=\"noopener\">VBA: come sostituire i caratteri in una stringa<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/vba-rimuove-i-caratteri-speciali-dalla-stringa\/\" target=\"_blank\" rel=\"noopener\">VBA: come rimuovere caratteri speciali da una stringa<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/vba-converte-la-stringa-in-un-numero-intero\/\" target=\"_blank\" rel=\"noopener\">VBA: come convertire una stringa in int<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi in VBA per confrontare le stringhe: Metodo 1: confronto tra stringhe con distinzione tra maiuscole e minuscole SubCompareStrings () Dim i As Integer For i = 2 To 10 Range(&#8221; C &#8221; &amp; i) = StrComp(Range(&#8221; A &#8221; &amp; i), Range(&#8221; B &#8221; &amp; i)) = 0 Next i [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come confrontare stringhe in VBA (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come confrontare le stringhe utilizzando VBA, con esempi.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come confrontare stringhe in VBA (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come confrontare le stringhe utilizzando VBA, con esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T21:20:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/str1.png\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/\",\"url\":\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/\",\"name\":\"Come confrontare stringhe in VBA (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-10T21:20:46+00:00\",\"dateModified\":\"2023-07-10T21:20:46+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come confrontare le stringhe utilizzando VBA, con esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come confrontare le stringhe in vba: con esempi\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come confrontare stringhe in VBA (con esempi) - Statorials","description":"Questo tutorial spiega come confrontare le stringhe utilizzando VBA, con esempi.","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:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/","og_locale":"it_IT","og_type":"article","og_title":"Come confrontare stringhe in VBA (con esempi) - Statorials","og_description":"Questo tutorial spiega come confrontare le stringhe utilizzando VBA, con esempi.","og_url":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/","og_site_name":"Statorials","article_published_time":"2023-07-10T21:20:46+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/str1.png"}],"author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/","url":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/","name":"Come confrontare stringhe in VBA (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-10T21:20:46+00:00","dateModified":"2023-07-10T21:20:46+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come confrontare le stringhe utilizzando VBA, con esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/vba-confronta-le-stringhe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come confrontare le stringhe in vba: con esempi"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4470"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=4470"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4470\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}