Chr VBA Function – How to return a character from ASCII code

1. Chr VBA function – Description

The Chr VBA function   returns a character based on the position in an ASCII character array. For example, the letter “a” in the ASCII code table is position 97. If we would like to get the position in an array based on a character, we should use the VBA Asc function  . The ASCII character table is case sensitive, so uppercase characters have a different position than lowercase characters. The array contains both control characters and alphanumeric characters.

2. VBA Chr function – Syntax

'officeinside.org
Chr (CharCode As Long)

CharCode : A number representing the character position in the ASCII code table for which we want to obtain the character.

Function return : String / Text value.

3. VBA Chr function – Example

How to use Chr  function  in VBA Excel? Below are examples of using the Chr function in the VisualBasic Editor.

Example 1 : An example of using the Chr VBA function – result in the MsgBox window.

'officeinside.org
Dim intValue As Integer
intValue = 97
MsgBox Chr (intValue)

Example 2 : VBA Chr – function example – result in an Excel sheet.

'officeinside.org 
Dim intValue2 As Integer
intValue2 = 97
Range ("A1") = Chr (intValue2)
Excel VBA Functions - Chr VBA function
Excel VBA Functions – Chr VBA function

4. VB Chr function – Additional information

  • lack

5. Chr VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions.

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: