Strange Formula Problem

jaysh

New Member
Joined
Jul 30, 2006
Messages
16
It's me again. Just want to thank you guys again for being very helpful.

Have a weird problem.

If i'm in excel and do =sum(at:at) it comes out to a dollar amount of 42.99 (expected)

However, when i'm in VBA and doing:

Set freight = ws1.Range("AT:AT")

ws3.Range("B2") = Application.Sum(freight)

It comes pretty close to the number but instead it is something like 42.989932

The weird part is that there are no extra decimel places anywhere in column AT to give it these extra places. Any ideas?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

delaneyjm

Well-known Member
Joined
Apr 22, 2009
Messages
624
It's a floating point issue likely. All computer programs suffer from it. It stems from converting numbers from base 10 to binary. Sometimes it doesn't go as cleanly as humans interpret.
 

jaysh

New Member
Joined
Jul 30, 2006
Messages
16
So from what it sounds like, there is no fix for that? I mean the numbers are so close that I can't see it being a problem. However, I want to make sure that if I go into alot higher numbers, it wont be throwing it off by dollars.

Any help?

Thanks!
 

delaneyjm

Well-known Member
Joined
Apr 22, 2009
Messages
624
Checked over your file. VBA is returning a different value (albeit the same when formatted) compared to doing AutoSum.

You could use some form of rounding method after doing the Application.Sum or instead of this code:

Code:
Set freight = ws1.Range("AT:AT")
ws3.Range("B2") = Application.Sum(freight)

you could run
Code:
Set freight = ws1.Range("AT:AT")
ws3.Range("B2").Formula = "=SUM(AT:AT)"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,008
Messages
5,834,866
Members
430,324
Latest member
bosphoruskid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top