By: Lutfor Rahman Shimanto

In reply to harman.

Hello Harman

Thanks for visiting our blog and sharing your query. You want 0 as leading when returning a number against a character. Don’t worry! I have come up with two solutions:

Use of TEXTJOIN, TEXT & VLOOKUP Functions

Select an empty cell.

Insert the following formula: =TEXTJOIN("", 1, TEXT(VLOOKUP((IF(1, MID(B5, ROW(INDIRECT("1:" & LEN(B5))), 1))), $E$5:$F$30, 2, 0), "00"))

Drag the Fill Handle icon to copy the formula down.

Use of VBA User-Defined Function

Go to Developer, followed by Visual Basic.

Click on Insert followed by Module.

Insert the following code in the module and save it:
Option Explicit

Function AlphabetToNumber(ByVal sSource As String) As String

Dim x As Integer
Dim sResult As String

For x = 1 To Len(sSource)
Select Case Asc(Mid(sSource, x, 1))
Case 65 To 90:
sResult = sResult & Format(Asc(Mid(sSource, x, 1)) - 64, "00")
Case Else
sResult = sResult & Mid(sSource, x, 1)
End Select
Next

AlphabetToNumber = sResult

End Function

Return to the sheet and select an empty cell.

Insert the following formula: =AlphabetToNumber(UPPER(B5))

Hit Enter to see an output like the following GIF:

I hope the formulas and VBA code will fulfil your goal. I have attached the solution workbook; good luck.

DOWNLOAD SOLUTION WORKBOOK

Regards
Lutfor Rahman Shimanto
Excel & VBA Developer
ExcelDemy