Public Function DecimalToAny(ByVal InputDec As Long, ByVal ToBase As Integer) As String
'Input - InputDec - Any decimal value to be converted to new base
' - ToBase - The new base must be in range 2 - 36
'
'Output - String representation of the inputed decimal value in the new base.
' - Null value if wrong input encountered
'
On Error GoTo ErrHndl
Dim BaseStr As String
Dim Number As Long
If ToBase <2 Or ToBase > 36 Then
'ToBase must be in the range 2 - 36, so return Null String
DecimalToAny = vbNullString
Exit Function
End If
'All character bases up to 36
Const CharsSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do While InputDec
'Perform the Mod operation
Number = InputDec Mod ToBase
'Find the corresponding character in the new base
DecimalToAny = Mid$(CharSet, Number + 1, 1) & DecimalToAny
'Perform integer division and update InputDec
InputDec = InputDec \ ToBase
Loop
Exit Function
ErrHndl:
'Error handling - return Null string
DecimalToAny = vbNullString
End Function