 Ask Remember Me? thsftp Posts: 1, Reputation: 1 New Member #1 Jan 23, 2014, 01:21 AM
Convert Hexadecimal number Larger than 10 digits
Hi,

I'm new to Excel VBA, can anyone help me with converting large Hexadecimal Number in Excel 2007.

I've used the following code from this forum, it converts but not absolutely accurately:

code:

Public Function HexToDec(Hex As String) As Double

Dim I As Long
Dim j As Variant
Dim k As Long
Dim n As Long
Dim HexArray() As Double

n = Len(Hex)
k = -1
ReDim HexArray(1 To n)
For I = n To 1 Step -1
j = Mid(Hex, I, 1)
k = k + 1
Select Case j
Case 0 To 9
HexArray(I) = j * 16 ^ (k)
Case Is = "A"
HexArray(I) = 10 * 16 ^ (k)
Case Is = "B"
HexArray(I) = 11 * 16 ^ (k)
Case Is = "C"
HexArray(I) = 12 * 16 ^ (k)
Case Is = "D"
HexArray(I) = 13 * 16 ^ (k)
Case Is = "E"
HexArray(I) = 14 * 16 ^ (k)
Case Is = "F"
HexArray(I) = 15 * 16 ^ (k)
End Select
Next I
HexToDec = Application.WorksheetFunction.Sum(HexArray)

End Function

The above code gives the output as "1394546016882220" in Excel to the input Hexa Value "04F4550BF58E28", whereas the correct answer is "1394546016882216". JBeaucaire Posts: 5,426, Reputation: 997 Software Expert #2 Jan 23, 2014, 05:03 PM
Not sure you're going to get any better than that. Excel's precision is a known issue.

Numeric precision in Microsoft Excel - Wikipedia, the free encyclopedia

 Question Tools Search this Question Show Printable Version Email this Page Search this Question: Advanced Search

## Check out some similar questions!

A license plate has a three-digit number printer on it. The product of the digits is 210, their sum is 18, and the numbers appears in descending order from left to right. What is the license plate number?