Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003: Cell rounds 16 digit numbers- How to advoid rounding? Max T. Excel Discussion (Misc queries) 1 January 20th 10 05:40 PM
How to make random numbers stay the same wyobuff Excel Worksheet Functions 4 October 24th 08 06:19 AM
conditional formating colours to stay when numbers are deleted? Raj Excel Worksheet Functions 1 February 9th 06 01:19 PM
How do I get the numbers to stay in the lower left hand corner? kebis Excel Discussion (Misc queries) 1 April 14th 05 07:32 PM
How do I get numbers on a colum to stay as I typed them on an exc. Desperate School Secretary Excel Discussion (Misc queries) 1 April 7th 05 03:58 AM


All times are GMT +1. The time now is 09:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"