Version 2 works like a UDF and can be used in any column.
Function MapOriginal2Code_V2(rg As Range) As String
Const sOriginal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_1234567890"
Const sCode = "-P2KHd7ZG3s14WRVhqmaJe8rQUz_gpwuTtbXLkFEB56ylfAMc0YOCjvnNSDxIo9"
Dim i As Long, nPos As Long, sResult As String, sText As String
sText = rg.Value
For i = 1 To Len(sText)
nPos = InStr(1, sOriginal, Mid$(sText, i, 1))
If nPos Then
sResult = sResult & Mid$(sCode, nPos, 1)
Else
sResult = sResult & Mid$(sText, i, 1)
End If
Next i
MapOriginal2Code_V2 = sResult
End Function
Version 3 takes text in column A and places the code in column B.
Sub MapOriginal2Code_V3()
Const sOriginal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_1234567890"
Const sCode = "-P2KHd7ZG3s14WRVhqmaJe8rQUz_gpwuTtbXLkFEB56ylfAMc0YOCjvnNSDxIo9"
Dim i As Long, nPos As Long, sResult As String, j As Long, sText As String
For j = 1 To Cells(Rows.Count, "A").End(xlUp).Row
sText = Cells(j, "A")
sResult = ""
For i = 1 To Len(sText)
nPos = InStr(1, sOriginal, Mid$(sText, i, 1))
If nPos Then
sResult = sResult & Mid$(sCode, nPos, 1)
Else
sResult = sResult & Mid$(sText, i, 1)
End If
Next i
Cells(j, "B") = sResult
Next j
End Sub
Bookmarks