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
 
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

This UDF give wrong answer for 2.06 -->B.F instead B.ZF
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This UDF give wrong answer for 2.06 -->B.F instead B.ZF

I guess he skipped the Z
If Mid(Num, x, 1) = "." Then NTLL = NTLL & "." Else NTLL = NTLL & Replace(Chr(Mid(Num, x, 1) + 64), "@", "Z")
 
Upvote 0
Rick,

formula works perfectly for most of numbers... I notice if a whole number eg; 31.00 is entered the code shows as CZ, is there any way to include the .00, just to maker the code look consistant?
 
Upvote 0
If you ever wanted to change your replacement code you could this, the lowest value in the array corresponds to 0 and the highest to 9:

VBA Code:
Function PriceCode(r As String) As String
Dim x As Long, ReplacementChars()
ReplacementChars = Array("Z", "A", "B", "C", "D", "E", "F", "G", "H", "I")
PriceCode = r
For x = 0 To 9
    PriceCode = Replace(PriceCode, x, ReplacementChars(x))
Next x
End Function
 
Upvote 0
I notice if a whole number eg; 31.00 is entered the code shows as CZ, is there any way to include the .00, just to maker the code look consistant?

The result of 31.00 should be CA.ZZ

Try:

VBA Code:
Function NumAbc(Num As Variant) As String
NumAbc = Evaluate(Replace("=@(@(@(@(@(@(@(@(@(@(text(" & Num & ", ""#.00""),""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
Rick,

formula works perfectly for most of numbers... I notice if a whole number eg; 31.00 is entered the code shows as CZ, is there any way to include the .00, just to maker the code look consistant?
Assuming you want all of your numbers to have two decimal places (minimum), try this variation on my code...
VBA Code:
Function Num2Let(ByVal Num As Variant) As String
  Dim X As Long
  Num2Let = Format(Num, "0.00")
  For X = 1 To Len(Num2Let)
    If Mid(Num2Let, X, 1) <> "." Then Mid(Num2Let, X) = Replace(Chr(64 + Mid(Num2Let, X, 1)), "@", "Z")
  Next
End Function
 
Upvote 0
VBA Code:
Function PriceCode(r) As String
Dim x As Long, ReplacementChars()
ReplacementChars = Array("Z", "A", "B", "C", "D", "E", "F", "G", "H", "I")
PriceCode = Format(r, "0.00")
For x = 0 To 9
    PriceCode = Replace(PriceCode, x, ReplacementChars(x))
Next x
End Function
 
Upvote 0
If you want the formula.
And start with 0 if you only put decimals

Book1
AB
10.05Z.ZE
2Z.ZE
Hoja12
Cell Formulas
RangeFormula
B1B1=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(A1,"0.00"),"0","Z"),1,"A"),2,"B"),3,"C"),4,"D"),5,"E"),6,"F"),7,"G"),8,"H"),9,"I")
B2B2=NumAbc(A1)


VBA Code:
Function NumAbc(Num As Variant) As String
NumAbc = Evaluate(Replace("=@(@(@(@(@(@(@(@(@(@(text(" & Num & ", ""0.00""),""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,786
Messages
6,121,553
Members
449,038
Latest member
Guest1337

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