• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 78
  • Last Modified:

How to use ASC in a custom function in Excel VBA?

What is the proper way to use ASC in a custom function in Excel VBA?

I thought this would work, but it returns 0.

Function AASC()
    Dim LResult As Integer
    LResult = Asc("W")
End Function
0
Alex Campbell
Asked:
Alex Campbell
  • 2
2 Solutions
 
NorieVBA ExpertCommented:
To return the value from a function you do it like this.
Function AASC()
    Dim LResult As Integer
    LResult = Asc("W")
    AASC = LResult
End Function

Open in new window

0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try it like this...

Function AASC() As Integer
    AASC = Asc("W")
End Function

Open in new window

BTW what's the use of this function without an argument?

If you wish you may try this function like this...

Function AASC(letter As String) As Integer
    AASC = Asc(letter)
End Function

Open in new window


Then you can use this function in another macro like this...

Sub Test()
Dim LResult As Integer
LResult = AASC("W")
MsgBox LResult
End Sub

Open in new window

Or try it on the worksheet like this...

if your letter is in A2, then
=AASC(A2)

Open in new window

1
 
Alex CampbellAuthor Commented:
Thanks to both of you for your solutions.
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Alex!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now