VBA CHR Function

HomeVBA Functions LIST (Category Wise)How to use the VBA CHR Function (Syntax + Example)

What is VBA CHR Function

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.

how to use it

To use VBA's CHR function you need to understand its syntax and arguments:

Syntax

Chr(Char code)

Arguments

  • Char code: The char code for which you want to get the character.

Example to use CHR Function in VBA

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

Notes

Below are some important points which you need to take care while using CHR function in VBA.

  • It will return an error if the value supplied is out of the range (CharCode < 0 or CharCode > 255).

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.