Excel VBA ASC Function to get ASCII value of text

This page explains how to use Excel VBA ASCFunction to get ASCII value of a text, and how to check if a text contains an alphabet, number or symbol

What is Excel VBA ASC Function?

Excel VBA ASC Function returns the ASCII value of the first character in a text. ASCII (American Standard Code for Information Interchange) uses 8-bit code units, an old encoding system which stores mainly numbers, lowercase letters a to z, uppercase letters A to Z, basic punctuation symbols, control codes. Many old systems still use this encoding system. 8 bit means the computer memory uses “8” digits with 1 and 0 combination (binary) to represent a character, 8 bits memory is equal to 1 byte.

Refer to the below table, Excel ASC Function will convert the “Char” value to “Dec” value.

DecHexOctCharDescription
00000null
11001start of heading
22002start of text
33003end of text
44004end of transmission
55005enquiry
66006acknowledge
77007bell
88010backspace
99011horizontal tab
10A012new line
11B013vertical tab
12C014new page
13D015carriage return
14E016shift out
15F017shift in
1610020data link escape
1711021device control 1
1812022device control 2
1913023device control 3
2014024device control 4
2115025negative acknowledge
2216026synchronous idle
2317027end of trans. block
2418030cancel
2519031end of medium
261A032substitute
271B033escape
281C034file separator
291D035group separator
301E036record separator
311F037unit separator
3220040space
3321041!
3422042
3523043#
3624044$
3725045%
3826046&
3927047
4028050(
4129051)
422A052*
432B053+
442C054,
452D055
462E056.
472F057/
48300600
49310611
50320622
51330633
52340644
53350655
54360666
55370677
56380708
57390719
583A072:
593B073;
603C074<
613D075=
623E076>
633F077?
6440100@
6541101A
6642102B
6743103C
6844104D
6945105E
7046106F
7147107G
7248110H
7349111I
744A112J
754B113K
764C114L
774D115M
784E116N
794F117O
8050120P
8151121Q
8252122R
8353123S
8454124T
8555125U
8656126V
8757127W
8858130X
8959131Y
905A132Z
915B133[
925C134\
935D135]
945E136^
955F137_
9660140`
9761141a
9862142b
9963143c
10064144d
10165145e
10266146f
10367147g
10468150h
10569151i
1066A152j
1076B153k
1086C154l
1096D155m
1106E156n
1116F157o
11270160p
11371161q
11472162r
11573163s
11674164t
11775165u
11876166v
11977167w
12078170x
12179171y
1227A172z
1237B173{
1247C174|
1257D175}
1267E176~
1277F177DEL

Extended Character Set

DecHexUnicode Open in a new window...Char Zoom...Name
12880U+20ACEuro Sign
12981Undefined
13082U+201ASingle Low-9 Quotation Mark
13183U+0192ƒLatin Small Letter F With Hook
13284U+201EDouble Low-9 Quotation Mark
13385U+2026Horizontal Ellipsis
13486U+2020Dagger
13587U+2021Double Dagger
13688U+02C6ˆModifier Letter Circumflex Accent
13789U+2030Per Mille Sign
1388AU+0160ŠLatin Capital Letter S With Caron
1398BU+2039Single Left-pointing Angle Quotation Mark
1408CU+0152ŒLatin Capital Ligature Oe
1418DUndefined
1428EU+017DŽLatin Capital Letter Z With Caron
1438FUndefined
14490Undefined
14591U+2018Left Single Quotation Mark
14692U+2019Right Single Quotation Mark
14793U+201CLeft Double Quotation Mark
14894U+201DRight Double Quotation Mark
14995U+2022Bullet
15096U+2013En Dash
15197U+2014Em Dash
15298U+02DC˜Small Tilde
15399U+2122Trade Mark Sign
1549AU+0161šLatin Small Letter S With Caron
1559BU+203ASingle Right-pointing Angle Quotation Mark
1569CU+0153œLatin Small Ligature Oe
1579DUndefined
1589EU+017EžLatin Small Letter Z With Caron
1599FU+0178ŸLatin Capital Letter Y With Diaeresis
160A0U+00A0 No-break Space
161A1U+00A1¡Inverted Exclamation Mark
162A2U+00A2¢Cent Sign
163A3U+00A3£Pound Sign
164A4U+00A4¤Currency Sign
165A5U+00A5¥Yen Sign
166A6U+00A6¦Broken Bar
167A7U+00A7§Section Sign
168A8U+00A8¨Diaeresis
169A9U+00A9©Copyright Sign
170AAU+00AAªFeminine Ordinal Indicator
171ABU+00AB«Left-pointing Double Angle Quotation Mark
172ACU+00AC¬Not Sign
173ADU+00AD­Soft Hyphen
174AEU+00AE®Registered Sign
175AFU+00AF¯Macron
176B0U+00B0°Degree Sign
177B1U+00B1±Plus-minus Sign
178B2U+00B2²Superscript Two
179B3U+00B3³Superscript Three
180B4U+00B4´Acute Accent
181B5U+00B5µMicro Sign
182B6U+00B6Pilcrow Sign
183B7U+00B7·Middle Dot
184B8U+00B8¸Cedilla
185B9U+00B9¹Superscript One
186BAU+00BAºMasculine Ordinal Indicator
187BBU+00BB»Right-pointing Double Angle Quotation Mark
188BCU+00BC¼Vulgar Fraction One Quarter
189BDU+00BD½Vulgar Fraction One Half
190BEU+00BE¾Vulgar Fraction Three Quarters
191BFU+00BF¿Inverted Question Mark
192C0U+00C0ÀLatin Capital Letter A With Grave
193C1U+00C1ÁLatin Capital Letter A With Acute
194C2U+00C2ÂLatin Capital Letter A With Circumflex
195C3U+00C3ÃLatin Capital Letter A With Tilde
196C4U+00C4ÄLatin Capital Letter A With Diaeresis
197C5U+00C5ÅLatin Capital Letter A With Ring Above
198C6U+00C6ÆLatin Capital Ligature Ae
199C7U+00C7ÇLatin Capital Letter C With Cedilla
200C8U+00C8ÈLatin Capital Letter E With Grave
201C9U+00C9ÉLatin Capital Letter E With Acute
202CAU+00CAÊLatin Capital Letter E With Circumflex
203CBU+00CBËLatin Capital Letter E With Diaeresis
204CCU+00CCÌLatin Capital Letter I With Grave
205CDU+00CDÍLatin Capital Letter I With Acute
206CEU+00CEÎLatin Capital Letter I With Circumflex
207CFU+00CFÏLatin Capital Letter I With Diaeresis
208D0U+00D0ÐLatin Capital Letter Eth
209D1U+00D1ÑLatin Capital Letter N With Tilde
210D2U+00D2ÒLatin Capital Letter O With Grave
211D3U+00D3ÓLatin Capital Letter O With Acute
212D4U+00D4ÔLatin Capital Letter O With Circumflex
213D5U+00D5ÕLatin Capital Letter O With Tilde
214D6U+00D6ÖLatin Capital Letter O With Diaeresis
215D7U+00D7×Multiplication Sign
216D8U+00D8ØLatin Capital Letter O With Stroke
217D9U+00D9ÙLatin Capital Letter U With Grave
218DAU+00DAÚLatin Capital Letter U With Acute
219DBU+00DBÛLatin Capital Letter U With Circumflex
220DCU+00DCÜLatin Capital Letter U With Diaeresis
221DDU+00DDÝLatin Capital Letter Y With Acute
222DEU+00DEÞLatin Capital Letter Thorn
223DFU+00DFßLatin Small Letter Sharp S
224E0U+00E0àLatin Small Letter A With Grave
225E1U+00E1áLatin Small Letter A With Acute
226E2U+00E2âLatin Small Letter A With Circumflex
227E3U+00E3ãLatin Small Letter A With Tilde
228E4U+00E4äLatin Small Letter A With Diaeresis
229E5U+00E5åLatin Small Letter A With Ring Above
230E6U+00E6æLatin Small Ligature Ae
231E7U+00E7çLatin Small Letter C With Cedilla
232E8U+00E8èLatin Small Letter E With Grave
233E9U+00E9éLatin Small Letter E With Acute
234EAU+00EAêLatin Small Letter E With Circumflex
235EBU+00EBëLatin Small Letter E With Diaeresis
236ECU+00ECìLatin Small Letter I With Grave
237EDU+00EDíLatin Small Letter I With Acute
238EEU+00EEîLatin Small Letter I With Circumflex
239EFU+00EFïLatin Small Letter I With Diaeresis
240F0U+00F0ðLatin Small Letter Eth
241F1U+00F1ñLatin Small Letter N With Tilde
242F2U+00F2òLatin Small Letter O With Grave
243F3U+00F3óLatin Small Letter O With Acute
244F4U+00F4ôLatin Small Letter O With Circumflex
245F5U+00F5õLatin Small Letter O With Tilde
246F6U+00F6öLatin Small Letter O With Diaeresis
247F7U+00F7÷Division Sign
248F8U+00F8øLatin Small Letter O With Stroke
249F9U+00F9ùLatin Small Letter U With Grave
250FAU+00FAúLatin Small Letter U With Acute
251FBU+00FBûLatin Small Letter U With Circumflex
252FCU+00FCüLatin Small Letter U With Diaeresis
253FDU+00FDýLatin Small Letter Y With Acute
254FEU+00FEþLatin Small Letter Thorn
255FFU+00FFÿLatin Small Letter Y With Diaeresis

Why do you need Excel VBA ASC Function?

The main use of Excel Code Function is to convert alphabet into number. For example, you may want to know if a string contains A to Z, you can simply check if ASCII code is between 65 to 90, same for symbols.

Another use is to check unknown text. Some text looks like a space but underneath it may be something else, which is caused by conversion of other database type to Excel. After checking the ASCII code of that string, you can use Replace function to get rid of it.

Syntax of Excel VBA ASC Function

ASC(text)

Text   The text which you want to convert into ASCII code

Note that ASC Function only returns the ASCII code of the first character in the text.

In Excel worksheet, ASC Function is called Code.

Example of Excel ASC Function

VBA CodeResultExplanation
ASC(“A”)65
ASC(“Z”)90
ASC(UCASE(Range(“A1”).Value))>=65 AND ASC(UCASE(Range(“A1”).Value))<=90)TRUE (assume A1 contains text “B”)Check if the first text in Cell A1 is an alphabet

Loop through each character in a text to see if the any character contains an alphabet, disregard case sensitivity.

Public Function wCheckAlphabet(var)
    For i = 1 To Len(var)
        If Asc(Mid(UCase(var), i, 1)) >= 65 And Asc(Mid(UCase(var), i, 1)) <= 90 Then
            wCheckAlphabet = True
            Exit Function
        Else
            wCheckAlphabet = False
        End If
    Next i
End Function

Outbound References

https://support.office.microsoft.com/en-us/article/CODE-function-daabc849-79e2-4661-8145-0b33c8397d4b?CorrelationId=2f7d4c56-6976-4a7f-948b-38b2b1da0be1&ui=en-US&rs=en-001&ad=US

Leave a Reply

Your email address will not be published. Required fields are marked *