To add a new line in VBA's Debug.Print, concatenate the built-in constant vbCrLf (or vbNewLine) between your strings, or call Debug.Print with no arguments to output a blank line. For example, Debug.Print "Line one" & vbCrLf & "Line two" writes two lines to the Immediate Window, while Debug.Print "Line one" followed by Debug.Print "Line two" achieves the same result because each Debug.Print statement already ends its output with a line break. The rest of this guide covers the exact syntax, the differences between the new-line constants, and the mistakes that make output run together or disappear.
What You'll Need
- Microsoft Excel (any modern desktop version) with the Visual Basic Editor available. The VBE is not present in Excel for the web or on mobile, so use the desktop app.
- The Developer tab enabled, or press Alt+F11 to open the editor directly.
- A module to work in: in the VBE choose Insert > Module.
- The Immediate Window visible: in the VBE choose View > Immediate Window, or press Ctrl+G.
Step-by-Step
- Open the Visual Basic Editor. In Excel press Alt+F11. The editor opens in its own window. Menu labels can differ slightly by version and region, but the layout is consistent across recent desktop releases.
- Insert a module. Choose Insert > Module. A blank code pane appears. All the examples below go in this module.
- Show the Immediate Window. Choose View > Immediate Window (Ctrl+G). This is where
Debug.Printoutput appears. If it is hidden, you will see nothing and assume the code failed. - Write a simple two-line test. Type this procedure:
Sub TestNewLine() Debug.Print "First line" & vbCrLf & "Second line" End SubThe ampersand joins the strings, andvbCrLfinserts a carriage return plus line feed between them. - Run it. Place the cursor inside the procedure and press F5. The Immediate Window shows First line on one row and Second line on the next.
- Try the blank-line method. Replace the body with:
Debug.Print "First line" Debug.Print Debug.Print "Second line"
A bareDebug.Printwith no arguments emits an empty line. This is the cleanest way to separate blocks of output. - Use a loop to build multiple lines. A common real-world pattern:
Dim i As Long For i = 1 To 3 Debug.Print "Row " & i & " value: " & Cells(i, 1).Value Next iEach iteration ends with its own line break automatically, so you do not needvbCrLfat the end of the string. - Choose the right constant.
vbCrLfis a carriage return plus line feed (Chr(13) & Chr(10));vbNewLineis the platform's new-line character and on Windows resolves to the same pair;vbLfis a line feed only. In the Immediate Window all three break the line, but when writing to a text file or a cell, the difference matters: Windows tools expectvbCrLf, while some Unix-oriented consumers expectvbLf. - Clear the window between runs. Add
Debug.Printwith no arguments at the top of the procedure, or right-click the Immediate Window and choose Clear, so old output does not mix with new. - Verify the output. Compare what you see against what you expected. If lines run together, the separator is missing or was placed inside a quoted string incorrectly.
Common Mistakes
- Putting the constant inside the quotes.
Debug.Print "First" & "vbCrLf" & "Second"prints the literal text vbCrLf, not a line break. The constant must sit outside the quotation marks. - Using a backslash-n. VBA does not interpret
\nas a new line. UsevbCrLf,vbNewLine,vbLf, orChr(10). - Expecting a trailing blank line. Each
Debug.Printalready ends with a line break, so addingvbCrLfat the end of a single string produces an extra empty line you may not want. - Looking in the wrong window. Output goes to the Immediate Window, not the Code pane or the Locals window. If nothing appears, press Ctrl+G.
- Forgetting to compile. A syntax error stops the procedure before any output. Choose Debug > Compile VBAProject to catch it first.
- Assuming Debug.Print affects the worksheet. It writes only to the Immediate Window; nothing appears in cells unless you assign values separately.
Tips
- Use
Debug.Printwith no arguments as a visual separator between test runs. - Build a helper function such as
Function NL() As String: NL = vbCrLf: End Functionif you prefer a shorter token, though the built-in constants are already short. - For multi-line output in a message box, the same constants work:
MsgBox "A" & vbCrLf & "B". - When writing to a text file with
Print #, usevbCrLffor Windows-friendly files. - Comment out or remove
Debug.Printlines before distributing a workbook; they add no value to end users and slow large loops slightly. - Combine
Debug.PrintwithDebug.Assertto pause execution when a condition fails, making line-by-line output easier to inspect.
Troubleshooting
If nothing appears in the Immediate Window, first confirm the window is open (View > Immediate Window). Next, check that the procedure actually ran: place a breakpoint with F9 and step through with F8. If the code runs but output is blank, verify you are not printing an empty variable. If lines run together, the separator is either missing or quoted; move vbCrLf outside the quotes. If you see the literal text vbCrLf, you quoted it. If the editor reports a compile error, check that the module is not missing a Sub or End Sub. If output appears only once despite a loop, confirm the loop counter changes and that Debug.Print is inside the loop body. If the Immediate Window shows old results, clear it before rerunning. Finally, if the workbook is shared or protected, macros may be disabled: check the Trust Center macro settings, but only enable macros from sources you trust.
Frequently Asked Questions
What is the difference between vbCrLf and vbNewLine?
On Windows they produce identical output (carriage return plus line feed). vbNewLine is described as the platform's new-line character, so it is the more portable choice in cross-platform code. vbCrLf is explicit and is the safer pick when writing files meant for Windows tools.
Can I use Debug.Print to write to a cell?
No. Debug.Print writes only to the Immediate Window. To place text in a cell, assign it directly, for example Range("A1").Value = "First" & vbCrLf & "Second", and turn on Wrap Text if you want both lines visible.
Why does my output show the word vbCrLf instead of a line break?
Because it is inside quotation marks. Anything between quotes is treated as literal text. Remove the quotes around the constant so VBA evaluates it.
Does Debug.Print slow down my macro?
It adds a small overhead per call. In tight loops with thousands of iterations the effect is noticeable, so print only what you need or guard the calls with a flag you can switch off.
How do I print a blank line?
Use Debug.Print with no arguments. It emits an empty line and is clearer than concatenating an empty string.
Can I clear the Immediate Window from code?
Not with a single built-in statement. The usual approach is to send the Ctrl+G focus and clear command via the editor, or simply print a separator line. Right-clicking the window and choosing Clear is the manual method.