Asc VBA function – How to return a sign in an ASCII code

Last Updated on January 11, 2023 by token

1. Asc VBA function – Description

The Asc VBA function   returns the position of a character in an ASCII character array . For example, the letter “a” is position 97 in the ASCII code table. If we would like to get a letter from the position in an array, we should use VBA Chr . 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. In case the argument has more than one character, ASC will return the position in the array for the first character indicated in the argument.

2. VBA Asc Function – Syntax

'officeinside.org 
Asc (String As String) As Integer

String : The character for which we want to get the number representing the position in the ASCII code table.

Function return : Integer / Integer numeric value.

3. VBA Asc function – Example

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

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

'officeinside.org
Dim strValue As String
strValue = "a"
strValue = "abc"
MsgBox Asc (strValue)

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

'officeinside.org 
Dim strValue2 As String
strValue2 = "a"
strValue2 = "abc"
Range ("A1") = Asc (strValue)
Excel VBA functions - Asc VBA function
Excel VBA functions – Asc VBA function

4. VB Asc function – Additional information

  • In case the argument is more than one character, ASC will return the position in the array for the first character in the argument.

5. Asc VisualBasic function – Where to use?

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

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: