macro to convert string to dec

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

I have cells that contain non-displaying characters, like line feeds.
How can I determine all the dec values in a cell?
Example, "abc" would be 97 98 99
That's obvious, the "abc" would just show up.
I want to also determine all the non-display characters like line feeds and
charriage returns in a given cell.
 
Your ultimate goal (all decimal values/only non-displaying character's
values) is not completely clear to me. The Asc function can be used to find
the ASCII/ANSI value of an individual character. The following function will
display these values (surrounded by angle brackets) for each character in
the text passed into it...

Function FindNonPrintableChars(TextIn As String) As String
Dim X As Long
For X = 1 To Len(TextIn)
FindNonPrintableChars = FindNonPrintableChars & _
"<" & Asc(Mid$(TextIn, X, 1)) & ">"
Next
End Function

If you only want to see the values for the non-displaying characters, then
this function will probably do what you want...

Function FindNonPrintableChars(TextIn As String) As String
Dim X As Long
Dim Letter As String
For X = 1 To Len(TextIn)
Letter = Mid$(TextIn, X, 1)
If Asc(Letter) < 32 Then
FindNonPrintableChars = FindNonPrintableChars & _
"<" & Asc(Mid$(TextIn, X, 1)) & ">"
Else
FindNonPrintableChars = FindNonPrintableChars & Letter
End If
Next
End Function


Rick
 
Thanks Rick,
I was able to find this function on the web,and it worked fine for me

Dim i As Long
Dim x() As Byte
x = StrConv(Range("a3").Value, vbFromUnicode) ' Convert string.
For i = 0 To UBound(x)
Debug.Print x(i)
Next
 
Yes, a Byte array solution will also work (assuming you want all characters
to be converted to their ASCII/ANSI decimal values).

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top