VBA New Line / Carriage Return

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 26, 2021

When working with strings in VBA, use vbNewLine, vbCrLf or vbCR to insert a line break / new paragraph.

This article will also discuss how to use use the line continuation character in order to continue a statement in your actual VBA code on a new line.

Using vbNewLine

The following code shows you how you would use vbNewLine in order to put the second text string on a new line in the Immediate window:

Sub UsingvbNewLine()

Dim StringOne As String
Dim StringTwo As String

StringOne = "This is String One"
StringTwo = "This is String Two"

Debug.Print StringOne & vbNewLine & StringTwo

End Sub

The result is:

Using vbNewLine in VBA to add new lines

Using vbCrLf

The following code shows you how you would use vbCrLf in order to put the second text string on a new line in a shape:

Sub UsingvbCrLf()

Dim StringOne As String
Dim StringTwo As String

StringOne = "This is String One"
StringTwo = "This is String Two"

ActiveSheet.Shapes.AddShape(msoShapeRectangle, 15, 15, 100, 50).Select

With Selection
.Characters.Text = StringOne & vbCrLf & StringTwo
End With

End Sub

The result is:

Using vbCrLF to add new lines in VBA

Using vbCR

The following code shows you how you would use vbCR in order to put the second text string on a new line in a message box:

Sub UsingvbCR()

Dim StringOne As String
Dim StringTwo As String

StringOne = "This is String One"
StringTwo = "This is String Two"

MsgBox StringOne & vbCr & StringTwo

End Sub

The result is:

Using vbCR to insert a new line in VBA

Continuing a Statement in VBA

You can use the line continuation character (“_” aka the underscore) to continue a statement from one line to the next in your VBA code. The following code shows you how to use the line continuation character:

Sub LineContinuation ()

If Range("b1").Value > 0 Then _
   Range("c1").Value = "Greater Than Zero"
End Sub

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples