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
pnuts
  • 58,317
  • 11
  • 87
  • 139
darknumbers
  • 33
  • 1
  • 1
  • 4

1 Answers1

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

neuralgroove
  • 580
  • 4
  • 12
  • Thanks for pointing out the error. It tried the code again but it still gives me "#NAME" value error. – darknumbers Nov 27 '15 at 19:54
  • 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 – neuralgroove Nov 27 '15 at 20:03
  • Thanks! I forgot to enable the macro. Now the problem is resolved. Thank you very much! – darknumbers Nov 27 '15 at 20:21