adding 2 variables gives wrong answer

Bernieg

Board Regular
Joined
Jan 1, 2009
Messages
147
Office Version
  1. 365
Platform
  1. Windows
Hi
I'm trying to get a simple sum to work, but the answer avades me
goodprod = 360 & optime = 625
goodprod / optime = 125

but the answer i get is 0.575999975204467

Cheers
Bernie





optime = Range("bm3").Value * 1440 'cell formatted to [m]
For r = 3 To lr
If Not IsEmpty(Cells(r, 6)) And Not IsEmpty(Cells(r, 7)) And IsEmpty(Cells(r, 66)) Or Cells(r, 66).Value <= 0 Then
Cells(r, 67).Value = empty
ElseIf Not IsEmpty(Cells(r, 6)) And Not IsEmpty(Cells(r, 7)) And Not IsEmpty(Cells(r, 66)) Then
Range("bo3").Value = (goodprod / optime)
End If
Exit For
Next
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
adding 2 variables gives wrong answer

Probably because you're not ADDING them, but DIVIDING them!

Range("bo3").Value = (goodprod / optime)

Try:

Range("bo3").Value = (goodprod + optime)
 
Upvote 0
I'm very confused as to why you would expect 360 divided by 625 would come to 125???

Dom
 
Upvote 0
Agree with Dom..

I think you need to explain the logic behind your math.

This line
Code:
optime = Range("bm3").Value * 1440 'cell formatted to [m]
Indicates you're dealing with times, so math can get strange.
And formatting a cell to [m] does not change the actual underlying value, it only changes the way it is displayed.
625 Minutes is actually 0.434028...
 
Upvote 0
Agree with Dom..

I think you need to explain the logic behind your math.

This line
Code:
optime = Range("bm3").Value * 1440 'cell formatted to [m]
Indicates you're dealing with times, so math can get strange.
And formatting a cell to [m] does not change the actual underlying value, it only changes the way it is displayed.
625 Minutes is actually 0.434028...
Hi guys

Yes the morning after the night before i'm afraid.
Is there a way to convert [m] formatted cell to general format.
i.e 0:45 in general is 0.03125, as i want a conversion to general giving a value of 45
Bernie
 
Upvote 0
looks like you were doing it with your code (*1440)

you could just put a formula in an adjescent column
=A1*1440
and format that cell as general
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,147
Members
452,891
Latest member
JUSTOUTOFMYREACH

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
Back
Top