VBA New Line / Carriage Return

Associated Files Download Links

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:

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:

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:

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:

You may also like some of this related content...

Advertisements
Automate Excel
Left Menu Icon