Code rounds to whole numbers, need it to stay with decimals

  • Thread starter Thread starter L. Howard
  • Start date Start date
L

L. Howard

I wrote this code to select a row in column A and add/subtract a specific amount to that row value and all the rows below it.

I now find that if the number is say 2.5 it adds 3. Or 1.3 is added as 1.

Is that fixable?

Thanks.
Howard


Sub Add_Subt()
Dim aRng As Range
Dim AddSub As Variant
Dim i As Long, j As Long
Dim myVals As Variant
Dim r As Range, c As Range

AddSub = Application.InputBox("Enter the row number where to start" & vbCr & _
"then a comma and the value " & vbCr & _
"you want to add or subtract with no space. " & vbCr & _
"Where row 9 and below you will add 11." _
& vbCr & vbCr & " Example 9,11 " _
& vbCr & " ", "We add & subtract", Type:=2)

If AddSub = "" Or AddSub = "False" Then Exit Sub

myVals = Split(AddSub, ",")

i = myVals(0)
j = myVals(1)

'MsgBox i & " " & j

Set r = Range("A" & i, Range("A1").End(xlDown))

For Each c In r
If c.Value > 0 Then
c.Value = c.Value + j
End If
Next

End Sub
 
Howard,
Look into data types 'Double' and 'Currency' to see if you get any
insight on how to approach handling the 'values'!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Howard,

Look into data types 'Double' and 'Currency' to see if you get any

insight on how to approach handling the 'values'!

Okay, will do.

Thanks,
Howard
 
Howard,

Look into data types 'Double' and 'Currency' to see if you get any

insight on how to approach handling the 'values'!


Dim j as Double fixed it.

Thanks, Garry

Howard
 

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

Back
Top