![]() |
macro to convert string to dec
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. -- Richard |
macro to convert string to dec
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 "Richard" wrote in message ... 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. -- Richard |
macro to convert string to dec
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 -- Richard "Rick Rothstein (MVP - VB)" wrote: 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 "Richard" wrote in message ... 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. -- Richard |
macro to convert string to dec
Yes, a Byte array solution will also work (assuming you want all characters
to be converted to their ASCII/ANSI decimal values). Rick "Richard" wrote in message ... 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 -- Richard "Rick Rothstein (MVP - VB)" wrote: 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 "Richard" wrote in message ... 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. -- Richard |
All times are GMT +1. The time now is 12:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com