Cell Value in workshet and VBA Cell Value differs

I

ifiaz

Hello,

Range("B2") contains the value 1852 in general format.

I am certain that this cell has no decimal places at all.
I even typed it explicitly once again.

But, when I do a

? Range("B2").Value

in VBA immediate window, it prints

1852.00034359738

This causes problems for me when I import the excel data to access as I
am actually expecting a whole number value in that cell.

Could someone explain this behaviour and how I can go about in fixing
it?

I am actually a proficient excel user and this is the first time I
encounter this.

Thanks.
 
D

Dave Peterson

If the column isn't wide enough, excel can truncate the disply--not the value.

If you widen the column, do you see all the digits?

If you select the cell, what do you see in the formula bar?

You can use some helper cells with formulas like:

=round()
=trunc()
=int()
=ceiling()
=floor()

to do some rounding.

See excel's help for more info. When you're looking at the help, click the "See
also" button for even more ways to round.
 
I

ifiaz

If the column isn't wide enough, excel can truncate the disply--not the value.
If you widen the column, do you see all the digits?

Widen or not. The cell contains only 1852. I typed '1' '8' '5' '2' and
[Enter]. Nothing more I typed. New worksheet with no formatting at all.
If you select the cell, what do you see in the formula bar?

I see 1852 only.
You can use some helper cells with formulas like:

=round()
=trunc()
=int()
=ceiling()
=floor()

to do some rounding.

See excel's help for more info. When you're looking at the help, click the "See
also" button for even more ways to round.

Thanks. I am aware of all these rounding functions which is not
necessary for me as, in the worksheet, the value is 1852 only. But,
only IN VBA the value shows up as 1852.00034359738 VERY STRANGE. I have
never experienced this before.
 
D

Dave Peterson

Sorry, I don't have another guess.
If the column isn't wide enough, excel can truncate the disply--not the value.

If you widen the column, do you see all the digits?

Widen or not. The cell contains only 1852. I typed '1' '8' '5' '2' and
[Enter]. Nothing more I typed. New worksheet with no formatting at all.
If you select the cell, what do you see in the formula bar?

I see 1852 only.
You can use some helper cells with formulas like:

=round()
=trunc()
=int()
=ceiling()
=floor()

to do some rounding.

See excel's help for more info. When you're looking at the help, click the "See
also" button for even more ways to round.

Thanks. I am aware of all these rounding functions which is not
necessary for me as, in the worksheet, the value is 1852 only. But,
only IN VBA the value shows up as 1852.00034359738 VERY STRANGE. I have
never experienced this before.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top