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.
- Char code: The char code for which you want to get the character.
To practically understand how to use the 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 used the value from cell A1 (149) and then we used the CHR function to convert that value into the character and it returned a bullet point • in the result.
- It would return an error if the value supplied is out of the range (CharCode < 0 or CharCode > 255).