View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Michel Pierron Michel Pierron is offline
external usenet poster
 
Posts: 214
Default hex to decimal

yes Tom, good remark and very simple.

Regards,
MP

"Tom Ogilvy" a écrit dans le message de
...
for less than 8 hexidecimal digits

hexnumber = "A1B5"
ActiveCell.Value = clng("&H" & hexnumber)

--
Regards,
Tom Ogilvy

"Michel Pierron" wrote in message
...
Hi Keivn,
A possible way:

Private Function HexToDec#(BinVal$)
Dim i%, Lg%
Lg = Len(BinVal)
For i = Lg To 1 Step -1
HexToDec = HexToDec + (Nb(Mid(BinVal, i, 1)) * (16 ^ (Lg - i)))
Next i
End Function

Private Function Nb%(i$)
Const Chain$ = "0123456789ABCDEF"
Nb = Val(InStr(1, Chain, i, 1) - 1)
End Function

Sub Test()
ActiveCell = HexToDec(ActiveCell)
End Sub

MP

"Keivn Green" a écrit dans le

message de
...
I need a macro that will convert a hex number to decimal.

I've tried
activecell= cdec(activecell)
with no luck...

I want to do it without having a formula in the cell do it.