Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Continue a Visual Basic Statement from One Line to the Next


View products that this article applies to.

This article was previously published under Q213640

↑ Back to the top


Summary

To make Microsoft Visual Basic for Applications procedures easier to read, you may want to continue a line of code from one line to the next. To write code in this way, use the line-continuation character.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To continue a statement from one line to the next, type a space followed by the line-continuation character [the underscore character on your keyboard (_)]. You can break a line at an operator, list separator, or period, as shown in the following statement:
Workbooks("MyBook.xls").Worksheets("Sheet1") _
   .Range("A1:B5").Value = _
   var1 + 3.14159
				
You cannot break statements in the middle of a keyword value or a text string. If you are using a long text string and need to continue the line, you can break the string into two strings and use a combination of the concatenation operator (&) and the line-continuation character, as shown in the following example:
var1 = "This is a long string that we are going to break"
MsgBox var1
var1 = "This is a long string th" & _
   "at we are going to break"
MsgBox var1
				

↑ Back to the top


Keywords: KB213640, kbprogramming, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213640
Revision : 6
Created on : 10/10/2006
Published on : 10/10/2006
Exists online : False
Views : 290