How to Use VBA Asc Function (5 Practical Examples)

In this article, we will discuss Excel VBA Asc Function. It is a convenient tool. I hope you will find the article interesting and can increase your Excel skill.


Download Practice Workbook

Please download the practice workbook to practice yourself.


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. So, it is a VBA function.

To find the ASCII value of a character or a text in an Excel worksheet, you can use the CODE function.


5 Ideal Examples to Use Excel VBA Asc Function

Let’s consider a dataset mentioned below. In this dataset, we have two columns B & C representing Name and Result after using VBA Asc. The dataset range is from B4 to C11.

Example to use VBA Asc Function


Example 1: Apply a Word Using VBA Asc Function

In this example, I will show the result by applying a word in excel Asc Function. I am going to describe the example step by step.

Steps:

  • First Go to the Developer.
  • Then Select the Macros.

Example to use VBA Asc Function

  • You will find this blank window just like the one given below.

Example to use VBA Asc Function

  • Type a macro name here.
  • Next, Select the Macros in the option to This Workbook.
  • Press on the Create

Example to use VBA Asc Function

  • You will find the window just like the one given below.

Example to use VBA Asc Function

  • Now write down the code given below:
Sub Code()
Dim Result1
Result1 = Asc("Robin")
MsgBox Result1
End Sub

Example to use VBA Asc Function

  • After that Run the code by pressing f5 The pop-up window will show the result just like the one given below.

Example to use VBA Asc Function

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

Example to use VBA Asc Function


Example 2: VBA Asc Function to Use a Capital Letter

Here, I will show the result for using a Capital letter in Excel Asc Function.

Steps:

  • We used a word in the previous example. In this example, I am using a Capital letter only.
  • Write down the code given below in Microsoft Visual Basic
Sub Code() 
Dim Result1 
Result1 = Asc("A") 
MsgBox Result1 
End Sub

  • After that, Press f5 to run the code.
  • A pop-up window will show the result just like the one given below.

Example to use VBA Asc Function


Example 3: Insert a Small Letter Using VBA Asc Function

Here, I will show the result for using Small letter in Excel Asc Function.

Steps:

  • Write down the code given below in Microsoft Visual basic window.
Sub Code()
Dim Result1
Result1 = Asc("a")
MsgBox Result1
End Sub

  • Then, Press f5 to run the code.
  • A pop-up window will show the result just like the one given below.


Example 4: Introduce a Symbol with VBA Asc Function

Here, I will show the result for using a Symbol in Excel Asc Function.

Steps:

  • Write down the code given below in Microsoft Visual Basic window.
Sub Code()
Dim Result1
Result1 = Asc("@")
MsgBox Result1
End Sub

  • After that, Press f5 to run the code.
  • A pop-up window will show the result just like the one given below.


Example 5: Apply VBA Asc Function to Insert a Blank Space

Here, I will show the result of using a Blank in Excel Asc Function.

Steps:

  • Write down the code given below in Microsoft Visual Basic
Sub Code()
Dim Result1
Result1 = Asc(" ")
MsgBox Result1
End Sub

  • After that, Press f5 to run the code.
  • A window showing the result “Invalid procedure call or argument” will come forward because of no argument in the function.


Further Readings


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.

Conclusion

I have tried to describe the Asc Function in this article with 5 suitable examples. I hope this will increase your Excel skill. If you have any kind of query, feel free to ask me in the comment section.

Kawser

Kawser

Hello! Welcome to my Excel blog! It took me some time to be a fan of Excel. But now I am a die-hard fan of MS Excel. I learn new ways of doing things with Excel and share them here. Not only how-to guide on Excel, but you will get also topics on Finance, Statistics, Data Analysis, and BI. Stay tuned! You can checkout my courses at Udemy: https://www.udemy.com/user/exceldemy/

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo