Ascii

  • Thread starter Syrus the Virus
  • Start date
S

Syrus the Virus

Hi guys and galls,

Question 1:

I know how to read what kind of ASCII is standing in a cell ( Example:
6 is 54 and z is 90) but what if I want it the other way around,
displaying the leter with the code 86 for example.

Question 2:

And what if I want to read a multiple filled cell. A cell with for
example VW as Value?

Question 3:

Can I rip the contens of the cell apart and check if the Carathers used
in a cell are for example letters ( like ASCII between 65 and 90)

Please
help!!!!.1.!>!!>!>!>!>!1>!1.11.1!>1!.1>111.1!!!!!!>1.!>!1>1>1!>.....1.1.!>!>!>!1.111>!!!>!>>!>!
 
J

Jake Marx

Hi Syrus,

Answers inline....
Question 1:
I know how to read what kind of ASCII is standing in a cell ( Example:
6 is 54 and z is 90) but what if I want it the other way around,
displaying the leter with the code 86 for example.

Use the Chr$() function instead of the Asc() function. If you select Asc in
your code and hit F1, you will be taken to the help for the Asc function.
From there, you can click See Also and read the help on Chr.
Question 2:
And what if I want to read a multiple filled cell. A cell with for
example VW as Value?

For this one, you can read the entire string into a variable and step
through it with a loop:

Sub test2()
Dim s As String
Dim n As Integer

s = Sheet1.Range("A1").Text
For n = 1 To Len(s)
MsgBox Asc(Mid$(s, n, 1))
Next n
End Sub
Question 3:
Can I rip the contens of the cell apart and check if the Carathers
used in a cell are for example letters ( like ASCII between 65 and 90)

Sub test3()
Dim s As String
Dim n As Integer
Dim nCode As Integer
Dim bBadData As Boolean

s = Sheet1.Range("A1").Text
For n = 1 To Len(s)
nCode = Asc(Mid$(s, n, 1))
If nCode < 65 Or (nCode > 90 And (nCode < 97 _
Or nCode > 122)) Then
bBadData = True
Exit For
End If
Next n

If bBadData Then MsgBox ("Invalid character(s)")
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
H

Harald Staff

1
=CHAR(86)
or
=CHAR(A1)
with 86 in cell A1
2+3
You'd need a macro for that I think.
 
C

Chip Pearson

You can use the Chr function to get the character corresponding
to an Ascii value. For example, Chr(65) will return an 'A'
character as a string.

You can loop through the characters in a string, ensuring that
each character is an uppercase letter. E.g.,

Dim S As String
Dim C As String
Dim N As Long

S = Range("A1").Text
For N = 1 To Len(S)
C = Mid(S, N, 1)
If Asc(C) >= 65 And Asc(C) <= 90 Then
' upper case character
Else
' not an upper case character
End If
Next N


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Syrus the Virus >"
 
Top