You are currently offline, waiting for your internet to reconnect

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

This article was previously published under Q141513
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
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 writecode in this way, use the line-continuation character.
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 bythe line-continuation character [the underscore character on your keyboard(_)]. In Microsoft Excel 5.0 and 7.0, you are limited to ten lines forcontinuation (that is, nine line-continuation characters). In MicrosoftExcel 97 and Microsoft Excel 98, this limit is increased to 21 line-continuation characters. You can break a line at an operator, listseparator, 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 textstring. 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 theconcatenation 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 var1var1 = "This is a long string th" & _   "at we are going to break"MsgBox var1				
XL97 XL98 XL7 XL5

Article ID: 141513 - Last Review: 10/11/2006 13:58:10 - Revision: 2.3

  • Microsoft Excel 5.0 Standard Edition
  • Microsoft Excel 5.0c
  • Microsoft Excel 5.0 Standard Edition
  • Microsoft Excel 5.0 for Macintosh
  • Microsoft Excel 5.0a for Macintosh
  • Microsoft Excel 95 Standard Edition
  • Microsoft Excel 95a
  • Microsoft Excel 97 Standard Edition
  • Microsoft Excel 98 for Macintosh
  • kbdtacode kbhowto kbprogramming KB141513