Line Continuation Character

Lines of VBA code can often be quite long and difficult to read so you are encouraged to use the line continuation character.
For any lines of code that are quite long you can use the line continuation character to split them into several lines.
VBA does not word wrap.
The line continuation character "_" is actually two characters.
There must always be a space before the underscore.
This is an underscore character that must be prefixed by a space (" _").
The line continuation character cannot be followed by any other characters (including comments).
You cannot have a line continuation character in the middle of a literal string.

Sub DoSomething(): Dim iNumber1 As Integer: Dim iNumber2 As Integer: _ 
iNumber1 = 5: iNumber2 = 10: Call MsgBox(iNumber1 + iNumber2): End Sub

Maximum of 24

You cannot include more than 24 line continuation characters in a single expression.

alt text

If you ever run into this limitation, you should use string concatenation instead.

Public Sub LineContinuation() 
Dim sMyString As String
    sMyString = "one" & _
                "two" & _
                "three" & _
                "four" & _
                "five" & _
                "six" & _
                "seven" & _
                "eight" & _
                "nine" & _
                "ten" & _
                "eleven" & _
                "twelve" & _
                "thirteen" & _
                "fourteen" & _
                "fifteen" & _
                "sixteen" & _
                "seventeen" & _
                "eighteen" & _
                "nineteen" & _
                "twenty" & _
                "twentyOne" & _
                "twentyTwo" & _
                "twentyThree" & _
                "twentyFour" & _
                "twentyFive" & _
End Sub

If you ever run into this limitation, you should consider passing in an object.

Public Sub PassingInArguments(byval iOne as Integer, _ 
                              byval iTwo as Integer, _
                              byval iThree as Integer, _
                              byval iFour as Integer, _
                              byval iFive as Integer, _
                              byval iSix as Integer _
                              byval iSeven as Integer, _
                              byval iEight as Integer, _
                              byval iNine as Integer, _
                              byval iTen as Integer, _
                              byval iEleven as Integer, _
                              byval iTwelve as Integer, _
                              byval iThirteen as Integer, _
                              byval iFourteen as Integer, _
                              byval iFifteen as Integer, _
                              byval iSixteen as Integer, _
                              byval iSeventeen as Integer, _
                              byval iEighteen as Integer, _
                              byval iNineteen as Integer, _
                              byval iTwenty as Integer, _
                              byval iTwentyOne as Integer, _
                              byval iTwentyTwo as Integer, _
                              byval iTwentyThree as Integer, _
                              byval iTwentyFour as Integer, _
                              byval iTwentyFive as Integer, _
End Sub

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext