2

I am trying to write a function using Excel VBA to convert a string to its respective ASCII number. For example:

"ABCD" => "65666768"

I have written this code but it's failed to do the conversion:

Public Function asciien(s As String) As String
' Returns the string to its respective ascii numbers
   Dim i As Integer

   For i = 1 To Len(s)
      asciien = asciien & CStr(Asc(Mid(s, x, 1)))
   Next i 

End Function
0

1 Answer 1

3

This line

asciien = asciien & CStr(Asc(Mid(s, x, 1)))

should read

asciien = asciien & CStr(Asc(Mid(s, i, 1)))

"x" has no value

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for pointing out the error. It tried the code again but it still gives me "#NAME" value error.
Check that you have the function name spelled right on the sheet and also that the code for the function is not in a sheet object, it should be in its own module
Thanks! I forgot to enable the macro. Now the problem is resolved. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.