View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ken Puls Ken Puls is offline
external usenet poster
 
Posts: 58
Default Excel dropping decimal places

You're dead on, Dave. Laying on robotman's mask caused the issue for
me, but switching to the Value2 cleared it up. Still need to make it a
double, though. :)

With the numberformat applied:
Dim val1 As Currency
val1 = Range("A1").Value
Debug.Print val1
~123.1235

Dim val2 As Double
val2 = Range("A1").Value
Debug.Print val2
~123.1235

And this time with Value2:
Dim val1 As Currency
val1 = Range("A1").Value2
~123.1235

Dim val2 As Double
val2 = Range("A1").Value2
Debug.Print val2
~123.123456

So, without setting it to a variable first:
? cdbl(range("A1").Value2)

Cheers,

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Dave Peterson wrote:
Try
?range("a1").value2

But that's close to the suggestion that Ken proffered.

" wrote:
No. In fact, I can go to the immediate windows and just:

? range("A1")

and Excel drops the decimals.

It seems like the source cell formatting may be part of the cause. I
have A1 formatted with:
$#,##0;$ "("#,##0")"

If I do a general format, Excel doesn't drop the decimal.

This is a really weird problem. Maybe an Excel bug?!

Why would formatting affect the value Excel returns?

Ideas?