View Full Version : Solved: Rounding up question

06-21-2005, 06:57 AM
When I run the code below it rounds up to the next dollar. I forget what you have to do to make it exact. Ex. 1621.89 instead of 1622.

Sub payout()
Dim bval As Long
Dim myrange As Variant
For Each myrange In Range("b6:b16")
If myrange <> "" Then
bval = myrange.Value + bval
End If

Next myrange
MsgBox "total is " & bval
End Sub


06-21-2005, 07:20 AM
Hi austenr,

With bval being Dim'med as a Long, it will always be a whole number. If you Dim it as a Double instead, you'll get the exact value.
You'll probably also want to do bval = Round(MyRange.Value, 2) + bval if your MyRange.Value is more than 2 decimal points.

06-21-2005, 07:29 AM
Thanks. I knew it had to do with the Dim but I had not tried Double. Solved

06-21-2005, 07:31 AM
You could also use Single or Currency, depending on the values you may be using to enter them. Each will work, I'd say take a look in the VBA help at the limits of each to determine which is best for your use