Download Practice Workbook
Introduction to VBA Asc Function
The VBA Asc function is a built-in function in Excel. This is a String/Text Function. We can use it as a VBA function (VBA) in Excel. This function can be used as a VBA function in Excel macros. We can also enter this code using the Microsoft Visual Basic Editor. The Microsoft Excel VBA Asc function returns the ASCII value of a character or the first character in a string passed as arguments.
Syntax & Arguments:
=Asc(string)
| ARGUMENT | REQUIRED OR OPTIONAL | VALUE |
|---|---|---|
| string | Required | If string consists of more than one character, the ASC(VBA) function returns the ASCII value of the first character in the string |
Types:
This function can’t be used as a worksheet function. You can only use it in VBA Subprocedures.
To find the ASCII value of a character or a text in an Excel worksheet, you can use the CODE function.
5 Examples to Use Excel VBA Asc Function
Example 1 – Apply a Word Using VBA Asc Function
Steps:
- Go to Developer.
- Select Macros.

- A new window will open.

- Enter a macro name.
- Select the Macros in the option to This Workbook.
- Click on the Create button.

- You will get the following window.

- Enter the code given below:
Sub Code()
Dim Result1
Result1 = Asc("Robin")
MsgBox Result1
End Sub

- Run the code by pressing f5.
The pop-up window will show the result.

- Run the code for both the name Kane and Aaron by changing the Name portion of the code.

Example 2 – VBA Asc Function to Use an Uppercase Letter
Steps:
- Enter the code given below in Microsoft Visual Basic.
Sub Code()
Dim Result1
Result1 = Asc("A")
MsgBox Result1
End Sub

- Press f5 to run the code.
- A pop-up window will open.

Example 3 – Insert a Lowercase Letter Using VBA Asc Function
Steps:
- Enter the code given below in the Microsoft Visual basic window.
Sub Code()
Dim Result1
Result1 = Asc("a")
MsgBox Result1
End Sub

- Press f5 to run the code.
- A pop-up window will display the result.

Example 4 – Introduce a Symbol with VBA Asc Function
Steps:
- Enter the code given below in theMicrosoft Visual Basic window.
Sub Code()
Dim Result1
Result1 = Asc("@")
MsgBox Result1
End Sub

- Press f5 to run the code.
- A pop-up window will display the result.

Example 5 – Apply VBA Asc Function to Insert a Blank Space
Steps:
- Enter the code given below in Microsoft Visual Basic Window.
Sub Code()
Dim Result1
Result1 = Asc(" ")
MsgBox Result1
End Sub

- Press f5 to run the code.
- A window will display the result “Invalid procedure call or argument” because there is no argument in the function.

Further Readings
- How to Use VBA UCASE function in Excel (4 Examples)
- Use MsgBox Function in Excel VBA (A Complete Guideline)
Things to Remember
- Asc(VBA) function is a VBA function. So, it can’t be used as a worksheet function. You can only use it in VBA Subprocedures.
- This function returns value only for the first letter of a string. This is why values for Aaron & A are the same.
- This function is case-sensitive.


