This article was previously published under Q210254
Moderate: Requires basic macro, coding, and interoperability skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Option Explicit
' Translates a letter to a digit.
Function XlateDigit(ByVal C As String) As String
C = UCase(C)
Select Case C
Case "A" To "P"
XlateDigit = Chr$((Asc(C) + 1) \ 3 + 28)
Case "R" To "Y"
XlateDigit = Chr$(Asc(C) \ 3 + 28)
Case "Q", "Z"
XlateDigit = "0"
Case Else
XlateDigit = C
End Select
End Function
' Applies the translated digit to a phone number.
Function PhoneLettersToDigits(ByVal PhoneNo As Variant) As Variant
Dim I as Integer
If VarType(PhoneNo) = 8 Then ' A string.
For I = 1 To Len(PhoneNo)
Mid(PhoneNo, I, 1) = XlateDigit(Mid(PhoneNo, I, 1))
Next I
End If
PhoneLettersToDigits = PhoneNo
End Function
? PhoneLettersToDigits("PRO-GRA-MMER")
Keywords: KB210254, kbprogramming, kbhowto