Skip to main content

Chr function

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Returns a String containing the character associated with the specified character code.

Syntax

Chr(charcode)
ChrB(charcode)
ChrW(charcode)

The required charcode argument is a Long that identifies a character.

Remarks

Numbers from 0–31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character. The normal range for charcode is 0–255. However, on DBCS systems, the actual range for charcode is -32768–65535.

The functions Asc(), AscB(), and AscW() are the opposite of Chr(), ChrB(), and ChrW(). The Asc() functions convert a string to an integer.

Example

This example uses the Chr function to return the character associated with the specified character code.

Dim MyChar
MyChar = Chr(65)    ' Returns A.
MyChar = Chr(97)    ' Returns a.
MyChar = Chr(62)    ' Returns >.
MyChar = Chr(37)    ' Returns %.

Leave a comment

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

Format your code: <pre><code class="language-vba">place your code here</code></pre>