Hi everyone!
Hope Everyone is good.
I have this UDF in my excel template that changes a set of numbers in to letters corresponding a code.
For example the code is "EUCHARISTO" it would simply mean
E=1, U=2, C=3, H=4, A=5, R=6, I=7, S=8, T=9, O=0 and by default the tenths position (".0")=X the hundredths position (.0"0") = Y and If a number repeats it becomes G.
Examples
12.50 = EUAY
123.00 = EUCXY
12.25 = EUGA
99.00 = TGXY
99.50 = TGAY
999.00 = TGTXY
999.99= TGTGT
Here's the UDF:
Also, I need advice where best to put this code, In a query or in a module.
Thank you all in advance!
Have a nice day!
Hope Everyone is good.
I have this UDF in my excel template that changes a set of numbers in to letters corresponding a code.
For example the code is "EUCHARISTO" it would simply mean
E=1, U=2, C=3, H=4, A=5, R=6, I=7, S=8, T=9, O=0 and by default the tenths position (".0")=X the hundredths position (.0"0") = Y and If a number repeats it becomes G.
Examples
12.50 = EUAY
123.00 = EUCXY
12.25 = EUGA
99.00 = TGXY
99.50 = TGAY
999.00 = TGTXY
999.99= TGTGT
Here's the UDF:
Code:
Function LetterCode(ByVal Numbers As String, Letters As String) As String
Dim X As Long
Numbers = Format(Numbers, "0.00") * 100
Letters = UCase(Right(Letters, 1) & Left(Letters, Len(Letters) - 1))
If Numbers Like "*0" Then Mid(Numbers, Len(Numbers)) = "Y"
If Numbers Like "*0?" Then Mid(Numbers, Len(Numbers) - 1) = "X"
For X = 1 To Len(Numbers)
If X > 1 Then If Mid(Numbers, X, 1) = Mid(Numbers, X - 1, 1) Then Mid(Numbers, X) = "Z"
If Mid(Numbers, X, 1) Like "#" Then
LetterCode = LetterCode & Mid(Letters, Mid(Numbers, X, 1) + 1, 1)
Else
LetterCode = LetterCode & Mid(Numbers, X, 1)
End If
Next
End Function
Also, I need advice where best to put this code, In a query or in a module.
Thank you all in advance!
Have a nice day!