Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code rounds to whole numbers, need it to stay with decimals
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code rounds to whole numbers, need it to stay with decimals
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code rounds to whole numbers, need it to stay with decimals
On Sunday, May 25, 2014 5:12:36 PM UTC-7, GS wrote:
Howard, Look into data types 'Double' and 'Currency' to see if you get any insight on how to approach handling the 'values'! -- Garry Okay, will do. Thanks, Howard |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code rounds to whole numbers, need it to stay with decimals
On Sunday, May 25, 2014 5:12:36 PM UTC-7, GS wrote:
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code rounds to whole numbers, need it to stay with decimals
On Sunday, May 25, 2014 5:12:36 PM UTC-7, GS wrote:
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 Hooray!<g -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2003: Cell rounds 16 digit numbers- How to advoid rounding? | Excel Discussion (Misc queries) | |||
How to make random numbers stay the same | Excel Worksheet Functions | |||
conditional formating colours to stay when numbers are deleted? | Excel Worksheet Functions | |||
How do I get the numbers to stay in the lower left hand corner? | Excel Discussion (Misc queries) | |||
How do I get numbers on a colum to stay as I typed them on an exc. | Excel Discussion (Misc queries) |