Excel VBA Chr Function
VBA Chr Function: The Chr function in VBA returns the character equivalent to a supplied character code between 0 and 255.
Syntax
Chr (CharCode)
Parameter
CharCode (required) – This parameter represents the character code for which you require the equivalent character.
Return
This function returns the character equivalent to a supplied character code between 0 and 255.
Example 1
Sub CharFunction_Example1() ' It will Return the characters for the codes 65 Dim char As String char = Chr(65) ' The variable char will return "A" Cells(1, 1).Value = char End Sub
Output
A
Example 2
Sub CharFunction_Example2() ' It will Return the characters for the codes 97 Dim char As String char = Chr(97) ' The variable char will return "a" Cells(1, 1).Value = char End Sub
Output
a
Example 3
Sub CharFunction_Example3() ' It will Return the characters for the codes -87 Dim char As String 'passing negative value char = Chr(-87) ' The variable char will return a run-time error. Cells(1, 1).Value = char End Sub
Output