I am trying to write a macro that converts a decimal number into a hexadecimal using Do Until-loop and select case
here is what I have so far when I run it the computer freezes up
Sub HexConverter()
Dim L As Double
Dim K As Integer
Dim N As Double
Dim R As Double
Dim A As Double
Dim P As String
Dim Hex As String
Dim HexRev As String
Dim i As Integer
N = Range("G5")
InputNum = N
Do
L = N
A = N / 16
K = Int(A)
If K < 16 Then
R = K
Else
R = A - K
R = R * 16
R = Round(R, 0)
End If
If R = 0 Then
P = "0"
Else
Select Case R
Case 1 To 9
P = CStr(R)
Case 10
P = "A"
Case 11
P = "B"
Case 12
P = "C"
Case 13
P = "D"
Case 14
P = "E"
Case 15
P = "F"
End Select
End If
If L = InputNum Then
Hex = P
Else
Hex = Hex & P
End If
Loop Until K = 0
For i = 1 To Len(Hex)
HexRev = Mid(Hex, i, 1) & HexRev
Next i
Range("G9") = HexRev
End Sub
here is what I have so far when I run it the computer freezes up
Sub HexConverter()
Dim L As Double
Dim K As Integer
Dim N As Double
Dim R As Double
Dim A As Double
Dim P As String
Dim Hex As String
Dim HexRev As String
Dim i As Integer
N = Range("G5")
InputNum = N
Do
L = N
A = N / 16
K = Int(A)
If K < 16 Then
R = K
Else
R = A - K
R = R * 16
R = Round(R, 0)
End If
If R = 0 Then
P = "0"
Else
Select Case R
Case 1 To 9
P = CStr(R)
Case 10
P = "A"
Case 11
P = "B"
Case 12
P = "C"
Case 13
P = "D"
Case 14
P = "E"
Case 15
P = "F"
End Select
End If
If L = InputNum Then
Hex = P
Else
Hex = Hex & P
End If
Loop Until K = 0
For i = 1 To Len(Hex)
HexRev = Mid(Hex, i, 1) & HexRev
Next i
Range("G9") = HexRev
End Sub