In this post, you’ll learn about the usage of vbNewLine, vbCrLf or vbCR to insert line break in your Excel spreadsheet using Excel VBA.
vbNewLine in Excel VBA
Below is a code snippet demonstrating how you can use vbNewLine to insert new line after the first string.
Sub InsertNewLinevbNewLine() Dim str1 As String Dim str2 As String str1 = "String 1" str2 = "String 2" Debug.Print str1 & vbNewLine & str2 End Sub
vbCrLf in Excel VBA
The below code snippet show how you can insert new line using vbCrLf using Excel VBA.
Sub InsertNewLinevbCrLf() Dim str1 As String Dim str2 As String str1 = "String 1" str2 = "String 2" Debug.Print str1 & vbCrLf & str2 End Sub
vbCR in Excel VBA
The below code snippet demonstrates how you can use vbCR to insert new line using Excel VBA.
Sub InsertNewLinevbCr() Dim str1 As String Dim str2 As String str1 = "String 1" str2 = "String 2" Debug.Print str1 & vbCr & str2 End Sub