Often we look to certain symbols in Excel that are hard to locate on the keyboard. Or the opposite – we look to find the Excel character codes for certain characters. In such cases we must usually revert to using the CHAR Excel function or the CODE Excel function. Let us explore these functions and how to use them both in Excel and VBA today.
Excel Character Codes
First let us start with exploring the Excel Character codes.
Converting Characters to Codes (Excel CODE function)
The Excel CODE function allows you to easily obtain the numeric code for the provided character (1 character string).
The syntax for the CODE function in VBA is:
CODE( string )
A single character string.
Below VBA equivalent of the Excel CODE Funtion – the Asc function
Debug.Print Asc("<") 'Result: 60
Converting Codes to Characters (Excel CHAR function)
The Excel CHAR function allows you to easily obtain the character represented by the numeric code.
The syntax for the CHAR function in Excel is:
A number from 0-255.
Below VBA equivalent of the Excel CHAR Funtion – the Chr function:
Debug.Print Chr(60) 'Result: <