Generate Alphabetical Codes Based on Numbers

Haree

Board Regular
Joined
Sep 22, 2019
Messages
146
Office Version
  1. 2016
Hi all I have to generate codes based on numbers based on the following standard

A,B,C,D,E,F,G,H,I,J
1,2,3,4,5,6,7,8,9,0

If i enter 11.03 it should show AA.JB
if i enter 67.85 it should show FG.HE

Thanks in advance.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
One way is to create our own function in VBA (a "User Defined Function" or "UDF").

So that code may look something like this:
VBA Code:
Function GenCode(entry As Variant) As String
'   Convert a numeric entry to a code

    Dim i As Long
    Dim c As String
    Dim x As String
    Dim str As String
    
    If Len(entry) > 0 Then
        For i = 1 To Len(entry)
            c = Mid(entry, i, 1)
            Select Case c
                Case "."
                    x = "."
                Case "0"
                   x = "J"
                Case "1", "2", "3", "4", "5", "6", "7", "8", "9"
                    x = Chr(64 + Val(c))
            End Select
            str = str & x
        Next i
    End If
    
    GenCode = str
    
End Function
Then we can use it in VBA or on the worksheet like any other Excel function, i.e
Excel Formula:
=GenCode(A1)
for value in cell A1
 
Upvote 0
Solution
For those who might be interested, here is a more compact way to write the GenCode function...
VBA Code:
Function GenCode(ByVal entry As Variant) As String
  Dim x As Long
  For x = 1 To Len(entry)
    If Mid(entry, x, 1) Like "[0-9]" Then Mid(entry, x) = Chr(64 + Mid(entry, x, 1))
  Next
  GenCode = Replace(entry, "@", "J")
End Function
 
Upvote 0
You are welcome.
Glad we were able to help.
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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