I am working on program that requires I use a Do-Until Loop to convert a decimal number to hexadecimal number. The following UDF makes Excel freeze up every time I run it, but it works great when I take out the do-until loop. Is there a better way to use a Do-Until Loop in this function?
Function DecHexConverter(DecValue As String) As String
Dim sTemp As String
Do Until DecValue = ""
If DecValue >= 16 Then
'if greater than 16 then recall function
sTemp = DecHexConverter(DecValue \ 16) & DecHexConverter(DecValue Mod 16)
ElseIf DecValue > 9 And DecValue < 16 Then
'if between 10 and 15 Assign A-F
Select Case DecValue
Case "10"
sTemp = "A"
Case "11"
sTemp = "B"
Case "12"
sTemp = "C"
Case "13"
sTemp = "D"
Case "14"
sTemp = "E"
Case "15"
sTemp = "F"
End Select
Else
'If between 0 and 9 no change
sTemp = DecValue
End If
Loop
DecHexConverter = sTemp
End Function
Bookmarks