VBA - Escape Characters

Each programming language has special ways of inserting special characters in a string. Examples of these could be "return"s or "tabs".

Here is a list of some of the most useful examples.

VBA Code        Alternative             Description
vbCr                   Chr(13)                   Carriage return
vbLf                   Chr(10)                   Linefeed character
vbCrLf               Chr(13) + Chr(10)  Carriage return
vbNewLine        Chr(13) + Chr(10)  Carriage feed / New Line
vbNullChar        Chr(0)                     Equivalent to 0.
vbNullString      -                              Empty String
vbTab                 Chr(9)                     Tab
vbBack               Chr(8)                     Backspace character

Note that different operating systems use a different combination of characters to symbolism a new line when pressing the return key.

The Chr() function turns a number into the same number ASCII code character.


This is a short example which shows a message box on multiple lines.

This outputs:

Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.

Must Read Articles

VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.
Installing VBA and First Program - What do you need to start using visual basic application VBA.