{"id":9398,"date":"2022-04-22T17:47:31","date_gmt":"2022-04-22T17:47:31","guid":{"rendered":"https:\/\/officetuts.net\/excel\/?p=9398"},"modified":"2024-03-30T00:27:23","modified_gmt":"2024-03-30T00:27:23","slug":"break-long-string-to-multiple-lines-in-vba","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/","title":{"rendered":"Break Long String to Multiple Lines in VBA"},"content":{"rendered":"\n

If you find any kind of problem or impediment in Excel and VBA<\/strong>, you will soon notice that there is always an easy way out and solution to it.<\/p>\n\n\n\n

Some of the issues that we can stumble upon are related to the view. In VBA<\/strong>, it is a good practice to keep a clean code and to make it visible and clear for everyone who might use it in the future.<\/p>\n\n\n\n

In the example below, we will show how to break a long string into multiple lines<\/strong> in VBA, to achieve what we said above.<\/p>\n\n\n\n

Break a Long String to Multiple Lines in VBA<\/h2>\n\n\n\n

First thing first, we need to open our module. To do this, we will simply click the ALT + F11<\/strong> combination on our keyboard, then right-click on the left window and go to Insert >> Module:<\/strong><\/p>\n\n\n\n

\"Graphical<\/figure>\n\n\n\n

Once there, we will write the things we need in the right-side window.<\/p>\n\n\n\n

We will define the text that will go into cell A1<\/strong> to be as follows:<\/p>\n\n\n\n

Range(\"a2\") = \"This is our text. As you will notice, it will be pretty large, and we will not be able to read everything without scrolling. This is a huge issue. We should separate it somehow.\"<\/code><\/pre>\n\n\n\n

In the module, this looks odd as well:<\/p>\n\n\n\n

\"Graphical<\/figure>\n\n\n\n

To show our sentences in different rows, we got to add a line break<\/strong>. This action is fairly easy to do in Excel. All you need to do is to type a space on your keyboard and follow it up with an underscore<\/strong>, so basically you need to type in \u201c _\u201d<\/strong> at the end of your sentence.<\/p>\n\n\n\n

Now, it is not enough to simply put the space and underscore at the end of each sentence, because if we do so and try to run our code, we will get the following message:<\/p>\n\n\n\n

\"Graphical<\/figure>\n\n\n\n

For our code to work, we need to make a few adjustments. We need to close in each line with the parentheses and start every sentence (except for the first one) with the \u201c&\u201d sign<\/strong>, so Excel knows it is a continuation of our sentence. This is what our final code will look like:<\/p>\n\n\n\n

Range(\"a3\") = \"This is our text. As you will notice,\" _\n& \"it will be pretty large, and we will not be able to read everything without scrolling.\" _\n& \" This is a huge issue. We should separate it somehow.\"<\/code><\/pre>\n\n\n\n

And in the module it will look like this:<\/p>\n\n\n\n

\"Graphical<\/figure>\n\n\n\n

As it can be seen, we have a lot better view of our text now, and we do not have to drag the text left or right.<\/p>\n\n\n\n

When we execute our code by clicking F5<\/strong> on our keyboard, we will have the same text in both cells (cells A2 and A3<\/strong>).<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Although you get the same result, remember that the whole point and importance of having the brake lines is to make your code neat and transparent, for yourself and for everyone else that might benefit from it.<\/p>\n","protected":false},"excerpt":{"rendered":"

If you find any kind of problem or impediment in Excel and VBA, you will soon notice that there is always an easy…<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[190],"yoast_head":"\nBreak Long String to Multiple Lines in VBA<\/title>\n<meta name=\"description\" content=\"Learn how to break a long string into multiple lines in VBA with this easy tutorial. Keep your code readable and clear for future users.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Break Long String to Multiple Lines in VBA\" \/>\n<meta property=\"og:description\" content=\"Learn how to break a long string into multiple lines in VBA with this easy tutorial. Keep your code readable and clear for future users.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-22T17:47:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-30T00:27:23+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png\" \/>\n<meta name=\"author\" content=\"Harun Spahic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harun Spahic\" \/>\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:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\"},\"author\":{\"name\":\"Harun Spahic\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2\"},\"headline\":\"Break Long String to Multiple Lines in VBA\",\"datePublished\":\"2022-04-22T17:47:31+00:00\",\"dateModified\":\"2024-03-30T00:27:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\"},\"wordCount\":426,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png\",\"keywords\":[\"pinterest\"],\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\",\"name\":\"Break Long String to Multiple Lines in VBA\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png\",\"datePublished\":\"2022-04-22T17:47:31+00:00\",\"dateModified\":\"2024-03-30T00:27:23+00:00\",\"description\":\"Learn how to break a long string into multiple lines in VBA with this easy tutorial. Keep your code readable and clear for future users.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage\",\"url\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png\",\"contentUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Break Long String to Multiple Lines in VBA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/officetuts.net\/excel\/#website\",\"url\":\"https:\/\/officetuts.net\/excel\/\",\"name\":\"\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/officetuts.net\/excel\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\",\"name\":\"Tomasz Decker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"caption\":\"Tomasz Decker\"},\"logo\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\"},\"description\":\"Spreadsheet and Python enthusiast.\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2\",\"name\":\"Harun Spahic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g\",\"caption\":\"Harun Spahic\"},\"sameAs\":[\"http:\/\/human.bsru.ac.th\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Break Long String to Multiple Lines in VBA","description":"Learn how to break a long string into multiple lines in VBA with this easy tutorial. Keep your code readable and clear for future users.","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:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/","og_locale":"en_US","og_type":"article","og_title":"Break Long String to Multiple Lines in VBA","og_description":"Learn how to break a long string into multiple lines in VBA with this easy tutorial. Keep your code readable and clear for future users.","og_url":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/","article_published_time":"2022-04-22T17:47:31+00:00","article_modified_time":"2024-03-30T00:27:23+00:00","og_image":[{"url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png"}],"author":"Harun Spahic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Harun Spahic","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/"},"author":{"name":"Harun Spahic","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2"},"headline":"Break Long String to Multiple Lines in VBA","datePublished":"2022-04-22T17:47:31+00:00","dateModified":"2024-03-30T00:27:23+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/"},"wordCount":426,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png","keywords":["pinterest"],"articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/","url":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/","name":"Break Long String to Multiple Lines in VBA","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png","datePublished":"2022-04-22T17:47:31+00:00","dateModified":"2024-03-30T00:27:23+00:00","description":"Learn how to break a long string into multiple lines in VBA with this easy tutorial. Keep your code readable and clear for future users.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#primaryimage","url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png","contentUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/graphical-user-interface-application-description-7.png"},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/break-long-string-to-multiple-lines-in-vba\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"Break Long String to Multiple Lines in VBA"}]},{"@type":"WebSite","@id":"https:\/\/officetuts.net\/excel\/#website","url":"https:\/\/officetuts.net\/excel\/","name":"","description":"","publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/officetuts.net\/excel\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42","name":"Tomasz Decker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","caption":"Tomasz Decker"},"logo":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/"},"description":"Spreadsheet and Python enthusiast."},{"@type":"Person","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2","name":"Harun Spahic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g","caption":"Harun Spahic"},"sameAs":["http:\/\/human.bsru.ac.th\/"]}]}},"_links":{"self":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/9398"}],"collection":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/comments?post=9398"}],"version-history":[{"count":3,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/9398\/revisions"}],"predecessor-version":[{"id":12985,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/9398\/revisions\/12985"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=9398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=9398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=9398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}