Excel VBA Asc Function
VBA Asc Function: The Asc function in VBA returns an integer showing the character code for the first character of a given string.
Syntax
Asc (String)
Parameter
String (required) – This parameter represents the text string for which you want to calculate the character code of the first character.
Return
This function returns an integer representing the character code for the first character of the specified string.
Example 1
Sub AscFunction_Example1() 'Returning the character codes for the first characters Dim val As Integer val = Asc("b") ' variable val will return 98 Cells(1, 1).Value = val End Sub
Output
98
Example 2
Sub AscFunction_Example2() 'Returning the character codes for the first characters Dim val As Integer val = Asc("ball") ' variable val will return 98 Cells(1, 1).Value = val End Sub
Output
98
Example 3
Sub AscFunction_Example2() 'Returning the character codes for the first characters Dim val As Integer val = Asc("Ball") ' variable val will return 66 Cells(1, 1).Value = val End Sub
Output
66