The VBA CHR function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it returns a character according to the character code you have supplied. In simple words, you can supply code ranging from 0 to 255 and it will return a character for that code.
To use VBA’s CHR function you need to understand its syntax and arguments:
- Char code: The char code for which you want to get the character.
To practically understand how to use VBA CHR function, you need to go through the below example where we have written a vba code by using it:
Sub example_CHR() Range("B1").Value = Chr(Range("A1")) End Sub
In the above example, we have used the value from cell A1 (149) and then we have used the CHR function to convert that value into the character and it has returned a bullet point • in the result.
- It will return an error if the value supplied is out of the range (CharCode < 0 or CharCode > 255).