# Convert Ascii to string

#### sharky12345

##### Well-known Member
I'm using this to convert a string to ascii;

Code:
``````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, i, 1)))
Next i

End Function``````
Can someone show me how to convert it back to string please?

#### shg

##### MrExcel MVP
 A​ B​ 1​ Now is the time for all good men … 2​ 078111119032105115032116104101032116105109101032102111114032097108108032103111111100032109101110032133 A2: =Str2AscDec(A1) 3​ Now is the time for all good men … A3: =AscDec2Str(A2) 4​ 5​ 6​ Now is the time for all good men … 7​ 4E6F77206973207468652074696D6520666F7220616C6C20676F6F64206D656E2085 A7: =Str2AscHex(A6) 8​ Now is the time for all good men … A8: =AscHex2Str(A7)

Code:
``````Function Str2AscHex(sInp As String) As String
Dim i           As Long

For i = 1& To Len(sInp)
Str2AscHex = Str2AscHex & Right\$("0" & Hex\$(Asc(Mid\$(sInp, i, 1&))), 2&)
Next i
End Function

Function AscHex2Str(sInp As String) As String
Dim i           As Long

For i = 1& To Len(sInp) Step 2&
AscHex2Str = AscHex2Str & Chr\$("&H" & Mid\$(sInp, i, 2&))
Next i
End Function

Function Str2AscDec(sInp As String) As String
Dim i           As Long

For i = 1& To Len(sInp)
Str2AscDec = Str2AscDec & Right\$("00" & Asc(Mid\$(sInp, i, 1&)), 3&)
Next i
End Function

Function AscDec2Str(sInp As String) As String
Dim i           As Long

For i = 1& To Len(sInp) Step 3&
AscDec2Str = AscDec2Str & Chr\$(Mid\$(sInp, i, 3&))
Next i
End Function``````

#### sharky12345

##### Well-known Member
Perfect - thanks!!

You're welcome.

1,081,545
Messages
5,359,450
Members
400,528
Latest member
Ratish52

### This Week's Hot Topics

• VBA (Userform)
Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
• List box that changes fill color
Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
• Remove duplicates and retain one. Cross-linked cases
Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
• VBA Copy and Paste With Duplicates
Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
• Macro
is it possible for a macro to run if the active cell value is different to the value above it
• IF DATE and TIME
I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...