Well --
finally I did myself the piece of code I whished for. Not quite elegent, but it certainly does work.
i did it to work just with letters, but changing 26 for whatever number you want, and modifying the mapping funcions it can work as a hexadecimal conversor or change the base to whatever suits you
Dim wsf As WorksheetFunction
'2015-04-14 / B.Agullo /
Public Function numberToLetters(ByVal n As Long) As String
'description here
Dim m As Long 'mod
Dim i As Long 'div
numberToLetters = ""
Set wsf = Application.WorksheetFunction
m = numMod(n, 26)
i = wsf.RoundDown(n / 26, 0)
numberToLetters = numberToLetters & numberToLetter(m)
While i > 26
m = numMod(i, 26)
i = wsf.RoundDown(i / 26, 0)
numberToLetters = numberToLetter(m) & numberToLetters
Wend
numberToLetters = numberToLetter(i) & numberToLetters
Set wsf = Nothing
End Function
'2015-04-14 / B.Agullo /
Public Function lettersToNumber(ByVal s As String) As Long
'description here
Dim i As Integer
Dim chrNum As Integer
Dim unitValue As Long
Dim chrV As Long
Dim chrS As String
chrNum = Len(s)
lettersToNumber = 0
For i = chrNum To 1 Step -1
unitValue = 26 ^ (i - 1)
chrS = Mid(s, chrNum - i + 1, 1)
chrV = letterToNumber(chrS)
lettersToNumber = lettersToNumber + unitValue * chrV
Next
End Function
'2015-04-14 / B.Agullo /
Public Function numMod(ByVal myNum As Long, ByVal myDivisor As Long) As Long
'description here
numMod = myNum - myDivisor * (wsf.RoundDown(myNum / myDivisor, 0))
End Function
'2015-04-14 / B.Agullo /
Public Function numberToLetter(ByVal n As Long) As String
'n = 1 for A, 26 for Z
numberToLetter = Chr(64 + n)
End Function
'2015-04-14 / B.Agullo /
Public Function letterToNumber(ByVal s As String) As Long
'n = 1 for A, 26 for Z
letterToNumber = Asc(s) - 64
End Function
numbersToLetter.xlsm
Bookmarks