Reputation: 35
I am having trouble with ascii to hex conversion with VBA. I need to convert a String, which combines letters and numbers to hex. However my code converts only about half of the string.
I have in A1 following Sting: BFEBFBFF000406E3
The code I have fills in A6: 42464542464246400000000000000000
I am using http://www.convertstring.com/cs/EncodeDecode/HexDecode to check if it is ok and there it translates as: 42464542464246463030303430364533DA
What do I have wrong please?
Sub strg()
Dim strg As String
Dim tmp As String
strg = Worksheets("List1").Range("A1")
Worksheets("List1").Range("A5").Value = strg
tmp = ""
For I = 1 To Len(strg)
tmp = tmp & hex((Asc(Mid(strg, I, 1))))
Next
Worksheets("List1").Range("A6").Value = tmp
End Sub
Thank you for any help.
Upvotes: 2
Views: 5855
Reputation: 35
Worksheets("List1").Range("A6").NumberFormat = "@" & tmp works prefectly, thank you Scott Craner
Upvotes: 1