Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - Hex Number Thinks Its Scientific


Group,
I use the following to convert a decimal summation into a hex
checksum. Only problem is when I report a number back like 7E15, excel
thinks its scientific notation and reports back 7000000000000000.
Decimal CheckSum = 32277, convert to Hex = 7E15, DisplayCheckSum reads
back 7000000000000000. How do I ensure a hex number instead of
scientific notation?

DisplayCheckSum = Right(Hex(CheckSum), 4)

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile: http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=488405

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VBA - Hex Number Thinks Its Scientific

I reproduced you problem and have a solution:

Sub Macro1()
Dim i As Long
i = 32277
displayCheckSum = Right(Hex(i), 4)
MsgBox (i)
MsgBox (displayCheckSum)
Cells(1, 1).Value = displayCheckSum
End Sub

If you run this and A1 is formatted General, then
7000000000000000 appears in the formula bar

But if you first format A1 as Text and run it then
7E15 appears in the formula bar
--
Gary's Student


"ajocius" wrote:


Group,
I use the following to convert a decimal summation into a hex
checksum. Only problem is when I report a number back like 7E15, excel
thinks its scientific notation and reports back 7000000000000000.
Decimal CheckSum = 32277, convert to Hex = 7E15, DisplayCheckSum reads
back 7000000000000000. How do I ensure a hex number instead of
scientific notation?

DisplayCheckSum = Right(Hex(CheckSum), 4)

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile: http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=488405


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default VBA - Hex Number Thinks Its Scientific

If the problem is entering the string in a cell you have to either preceed
it with an apostophe or set the cell's number format to text before entering
the string:

Sub a()
ActiveCell.Value = "'" & "7E15"
End Sub

Sub aa()
With ActiveCell
.NumberFormat = "@"
.Value = "7E15"
End With
End Sub


--
Jim
"ajocius" wrote in
message ...

Group,
I use the following to convert a decimal summation into a hex
checksum. Only problem is when I report a number back like 7E15, excel
thinks its scientific notation and reports back 7000000000000000.
Decimal CheckSum = 32277, convert to Hex = 7E15, DisplayCheckSum reads
back 7000000000000000. How do I ensure a hex number instead of
scientific notation?

DisplayCheckSum = Right(Hex(CheckSum), 4)

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile:
http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=488405



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - Hex Number Thinks Its Scientific


Gary and Jim,
Thank you for your assistance.
Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile: http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=488405

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default VBA - Hex Number Thinks Its Scientific

Found that making the cell number format text and then entering the number
has unpredictable results when it is a
a number like this: 0123456
Sometimes it works (displayed as above) and sometimes it doesn't (leading
zero stripped off).
The only sure way to handle this unfortunately seems to add a leading single
quote.

RBS


"Jim Rech" wrote in message
...
If the problem is entering the string in a cell you have to either preceed
it with an apostophe or set the cell's number format to text before
entering the string:

Sub a()
ActiveCell.Value = "'" & "7E15"
End Sub

Sub aa()
With ActiveCell
.NumberFormat = "@"
.Value = "7E15"
End With
End Sub


--
Jim
"ajocius" wrote in
message ...

Group,
I use the following to convert a decimal summation into a hex
checksum. Only problem is when I report a number back like 7E15, excel
thinks its scientific notation and reports back 7000000000000000.
Decimal CheckSum = 32277, convert to Hex = 7E15, DisplayCheckSum reads
back 7000000000000000. How do I ensure a hex number instead of
scientific notation?

DisplayCheckSum = Right(Hex(CheckSum), 4)

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile:
http://www.excelforum.com/member.php...o&userid=17695
View this thread:
http://www.excelforum.com/showthread...hreadid=488405






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
Formula to change scientific number to regular number or text Compare Values Excel Discussion (Misc queries) 2 August 23rd 07 06:10 PM
Number Formatting/Scientific notation Patrice Excel Discussion (Misc queries) 1 January 19th 07 08:55 PM
Help - Any number longer than 12 digits turns to scientific and ro LMH_VT Excel Discussion (Misc queries) 3 July 17th 05 03:58 PM
Global fix for scientific number format? Carol Excel Discussion (Misc queries) 1 April 14th 05 01:48 AM
convert scientific notation to a number Peter Excel Discussion (Misc queries) 1 January 4th 05 07:08 PM


All times are GMT +1. The time now is 09:33 PM.

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

About Us

"It's about Microsoft Excel"