Beating a dead horse, this code checks itself by converting the calculated decimal value back to hex and comparing it to the original function argument.
Code:
Function HexToDec(Hx As String) As Long
'convert Hex color code to decimal
Dim r As String, g As String, b As String, chk As String
If Len(Hx) <> 6 And Len(Hx) <> 7 Then
MsgBox "Input error to function HexToDec()" & vbCrLf & vbCrLf _
& "The hex value must be 6 characters long." & vbCrLf _
& "It optionally may have '#' on the left side making it 7 characters long.", _
vbOKOnly + vbInformation, " C H E C K F O R M A T "
Exit Function
End If
Hx = UCase(Replace(Hx, "#", ""))
r = Left(Hx, 2)
g = Mid(Hx, 3, 2)
b = Right(Hx, 2)
chk = Hex(("&H" & r & g & b)) 'convert result back to decimal and
If chk <> Hx Then 'compare with original input parameter
MsgBox "A conversion error has occured in function HexToDec()"
Else
HexToDec = ("&H" & r & g & b)
End If
End Function