Excel -- Converting letters to number

New Contributor

Hi, all.  Hoping I could find some help:  I need to convert a string of letters into numbers, and vice versa.  The set-up: the numbers 1,2,3,4,5,6,7,8,9,0 correspond to letters a,b,c,d,e,f,g,h,i,j.  Example: If a user enters hajg in the cell, the formula (or macro) produces 8107.  Or dibe produces 4925.


I can have two formulas, so the conversion doesn't have to go both ways in one formula.  I just need to do both.


Any ideas out there?

31 Replies

Hello Jason


Just a few nested SUBSTITUTE().



Mr. Lewin

nice formula!

then numbers to letters: =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,1,"a"),2,"b"),3,"c"),4,"d"),5,"e"),6,"f"),7,"g"),8,"h"),9,"i"),0,"j")

to extend - add equivalent numbers of "SUBSTITUTE(" to the formula

i.e. there are 10 substitutions - therefore 10 "SUBSTITUTE("

hope I am right... thanks

best response confirmed by Jason Summer (New Contributor)

Hi Jason,


If you familiar with VBA in Excel you can create a custom function to do this and use it in the worksheet.


This is my suggested function:

Option Compare Text

Function LettersToNumbers(text As String) As Integer
    Dim i As Integer
    Dim result As String
        For i = 1 To Len(text)
            Select Case Mid(text, i, 1)
             Case "a"
             result = result & 1
             Case "b"
             result = result & 2
             Case "c"
             result = result & 3
             Case "d"
             result = result & 4
             Case "e"
             result = result & 5
             Case "f"
             result = result & 6
             Case "g"
             result = result & 7
             Case "h"
             result = result & 8
             Case "i"
             result = result & 9
             Case "j"
             result = result & 0
            End Select
    LettersToNumbers = result
End Function


Please follow this link to figure out how to insert this function into your own workbook.

Also, you can place it in the Personal Macro Workbook so that the function will be available in all open workbook and this is described here in this link.


However, I've inserted it into the attached workbook.

Hope that helps



Thank you!  This is precisely what I was looking for.  I appreciate your help.




This works wonderfully!  Thank you for your help!

I was wondering about the numbers to letters -- I figured it was just like your suggestion, but I wasn't sure.  Thank you!

You can use =CODE(UPPER(A1))-64


It will work for uppercase and lowercase.

Hello Jason,

I suggest you use It has the ability to generate, modify, convert, render and print spreadsheets without using Microsoft Excel

@Haytham Amairah this is brilliant!   However, I couldn't figure out how to do numbers to letters, it show show #VALUE!...

Do you think you could shine some light?

Thank you so much!!!

@Jason Summer 

By the way, formulas could be




=TEXTJOIN("",TRUE,CHAR( MOD(MID(A2,ROW($A$1:INDEX($A$1:$A$8,LEN(A2))),1)-1,10)+1+96))


CSE (array) formula for pre-DA Excel



To do that, you need to change the above function as follows:

Function LettersToNumbers(text As String) As String
    Dim i As Integer
    Dim result As String
        For i = 1 To Len(text)
            Select Case Mid(text, i, 1)
             Case 1
             result = result & "a"
             Case 2
             result = result & "b"
             Case 3
             result = result & "c"
             Case 4
             result = result & "d"
             Case 5
             result = result & "e"
             Case 6
             result = result & "f"
             Case 7
             result = result & "g"
             Case 8
             result = result & "h"
             Case 9
             result = result & "i"
             Case 0
             result = result & "j"
            End Select
    LettersToNumbers = result
End Function


I guess that you have changed it like this but you forgot to change the function's return value data type from Integer to String, therefore, you got the #VALUE! error.



@Sergei Baklan 

Nice, can you modify this

=TEXTJOIN("",TRUE,CHAR( MOD(MID(A2,ROW($A$1:INDEX($A$1:$A$8,LEN(A2))),1)-1,10)+1+96))

if I want output in define set of letters in a given name range "mytable"

eg : cornflakes   c for 1, o for 2 and so on..

input : 123 output : cor



input output


this is the one I am using but how to make it reverse i.e numbers to letters


For such sample


formula in E2 could be


Thanks, but only first character is coming, I downloaded your file there also only first character is coming



That is array formula, you shall enter it with Ctrl+Shift+Enter instead of Enter.

Yes I did it in same manner, when I open your file it is read only where I can see it was correct the moment I click on edit the file it vanishes



Sorry. I missed this trick with N(IF1,..). Please check



@Sergei Baklan 


Great it is working ! but when I tried it in different cells I don't know why it is not working I changed all the reference cell addresses.. It is working only at A1



@Sergei Baklan 

I sometimes use LOOKUP as an alternative to INDEX when coercion is required.

= CONCAT( LOOKUP( VALUE(MID(number,k,1)), digits, characters ) )

The reverse decoding and I do not have to convert text to numbers

= CONCAT( LOOKUP( MID(text, k, 1), array ) )

but the elephant in that room is that I have had to sort the lookup data

It is OK for me to use 'array'

= SORT( IF( {0,1}, digits, characters ) )

but most users would be better off with a manual sort using a helper range.