Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default hex to decimal

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.



  #2   Report Post  
Posted to microsoft.public.excel.programming
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.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set automatic currancy decimal without entering the decimal? Giesej Excel Worksheet Functions 3 March 2nd 09 12:09 AM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
Batch converting CSV files from comma-decimal to period-decimal Nodles Excel Discussion (Misc queries) 3 July 5th 06 06:57 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM
FIXED 2 DECIMAL PLACES, MUST ENTER ALL ZEROES AFTER DECIMAL POINT. SUKYKITTY Excel Discussion (Misc queries) 3 July 6th 05 01:50 PM


All times are GMT +1. The time now is 11:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"