VBA built-in constants
VBA constants - used in text formatting
View ASCII values: Code 1 demonstrates conversion of VBA constant to its ASCII equivalent. The ASC function ASC(string) returns the integer representation of the first letter in a string.
Code 1: comments and
xlf_vbaConstants procedure
' ASCII characters =====
' Decimal 9: Horizontal Tab
' Decimal 10: Line Feed
' Decimal 13: Carriage Return
' Reference: https://excelatfinance.com/online2/xlf-char-function.php
' VBA constants ========
' vbCrLf: Carriage return/linefeed character combination
' vbCr: Carriage return character
' vbLf: Linefeed character
' vbNewLine: Newline character.
' vbTab: Tab character
Sub xlf_vbaConstants()
Dim a As Integer
Const xlfDblNLa As String = vbCrLf & vbCrLf ' Double line space ver.a
Const xlfDblNLb As String = vbNewLine & vbLf ' Double line space ver.b
a = Asc(Left(vbCrLf, 1)) ' returns 13
a = Asc(Right(vbCrLf, 1)) ' returns 10
a = Asc(vbCr) ' returns 13
a = Asc(vbLf) ' returns 10
a = Asc(vbNewLine) ' returns 13
a = Asc(Left(vbNewLine, 1)) ' returns 13
a = Asc(Right(vbNewLine, 1)) ' returns 10
a = Asc(vbTab) ' returns 9
a = Len(vbNewLine) ' returns 2
a = Len(xlfDblNLa) ' returns 4
a = Len(xlfDblNLb) ' returns 3
MsgBox "Line 1" & xlfDblNLb & "Line 2", , "xlfDblNL sample"
End Sub
- Download the file: xlf-constants.xlsm [44 KB]
- This example was developed in Excel 365 :: VBA 7.1
- Published: 17 May 2020
- Revised: Saturday 25th of February 2023 - 10:13 AM, [Australian Eastern Standard Time (EST)]
