decimal number to letters

Kiwi den

Board Regular
Joined
Feb 17, 2014
Messages
143
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I Have a cell (A1) that has a number in it (2.43) and I would like to display it as a code ( cost price) for example A.DC,, using 1=A, 2=B, 3=C, 4=D, 5=E, 6=F, 7=G, 8=H, 9=I, 0=Z

Is this possible using a formula or VBA

Thanks in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How about this?

VBA Code:
Function NTL(d As String) As String
Dim SP() As String: SP = Split(d, ".")
Dim tmp As String: tmp = vbNullString

For i = 0 To UBound(SP)
    For l = 0 To Len(SP(i)) - 1
        tmp = tmp & Chr(Mid(SP(i), l + 1, 1) + 64)
    Next l
    SP(i) = tmp
    tmp = vbNullString
Next i

NTL = Join(SP, ".")
End Function
 
Upvote 0
Hi Thanks, but how does this code activate to the required cells?
 
Upvote 0
Here is another UDF (user defined function) that you can consider...
VBA Code:
Function Num2Let(ByVal Num As Variant) As String
  Dim X As Long
  For X = 1 To Len(Num)
    If Mid(Num, X, 1) <> "." Then Mid(Num, X) = Chr(64 + Mid(Num, X, 1))
  Next
  Num2Let = Num
End Function
HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use Num2Let just like it was a built-in Excel function. For example,

=Num2Let(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
Here's a way to do with with Power Query as well. But I've noticed, that 0s get convertd to @s. The solution below converts from @ to Z, not sure how you wanted to deal with the 0s.

VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Converted = Table.AddColumn(Source, "Converted", each Text.Combine(List.Transform(Text.ToList(Text.From([Numeric])), each if _ = "." then "." else Text.Replace(Character.FromNumber(Number.From(_)+64),"@","Z"))))
in
    Converted

Book1
CD
1NumericConverted
24.02D.ZB
37.92G.IB
410AZ
54.21D.BA
64.81D.HA
74.26D.BF
89.8I.H
96.74F.GD
102.97B.IG
111.73A.GC
122.09B.ZI
132.91B.IA
148.36H.CF
159.46I.DF
161.96A.IF
177.34G.CD
185.86E.HF
193.79C.GI
208.99H.II
219.8I.H
227.69G.FI
232.64B.FD
243.72C.GB
Sheet4
 
Upvote 0
But I've noticed, that 0s get converted to @s.
I missed that in my original code!!! Here is my code modified to handle it...
VBA Code:
Function Num2Let(ByVal Num As Variant) As String
  Dim X As Long
  For X = 1 To Len(Num)
    If Mid(Num, X, 1) <> "." Then Mid(Num, X) = Replace(Chr(64 + Mid(Num, X, 1)), "@", "Z")
  Next
  Num2Let = Num
End Function
 
Upvote 0
Here is another UDF (user defined function) that you can consider...
VBA Code:
Function Num2Let(ByVal Num As Variant) As String
  Dim X As Long
  For X = 1 To Len(Num)
    If Mid(Num, X, 1) <> "." Then Mid(Num, X) = Chr(64 + Mid(Num, X, 1))
  Next
  Num2Let = Num
End Function
HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use Num2Let just like it was a built-in Excel function. For example,

=Num2Let(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
thanks works a treat
 
Upvote 0
Let's get it as close to 1 line as possible, lol.

VBA Code:
Function NTLL(ByVal Num As Variant) As String
For X = 1 To Len(Num)
  If Mid(Num, X, 1) = "." Then NTLL = NTLL & "." Else NTLL = NTLL & Replace(Chr(Mid(Num, X, 1) + 64), "@", "")
Next
End Function
 
Upvote 0
With formula
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,0,"Z"),1,"A"),2,"B"),3,"C"),4,"D"),5,"E"),6,"F"),7,"G"),8,"H"),9,"I")


And UDF without loop:

VBA Code:
Function NumAbc(num As Variant) As String
NumAbc = Evaluate(Replace("=@(@(@(@(@(@(@(@(@(@(" & num & ",0,""Z""),1,""A""),2,""B""),3,""C""),4,""D""),5,""E""),6,""F""),7,""G""),8,""H""),9,""I"")", "@", "SUBSTITUTE"))
End Function
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top