-
Rounding up question
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.
Code:
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
:banghead:
-
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
Code:
bval = Round(MyRange.Value, 2) + bval
if your MyRange.Value is more than 2 decimal points.
Matt
-
Thanks. I knew it had to do with the Dim but I had not tried Double. Solved
-
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