Solved

Rounding in formula

Posted on 2014-03-05
9
133 Views
Last Modified: 2014-03-06
I need to add rounding to the two columns below.  I tried to do it by adding another row, but got an #value error.

G and H

 Range("G" & srow).FormulaR1C1 = "=SUMIFS('Prior BDay'!C[-2],'Prior BDay'!C[-5],Summary!RC[-5],'Prior BDay'!C[-4],Summary!RC[-4])"
                    Range("G" & srow).FormulaR1C1 = "=ROUND(RC[-1],9)"


                    Range("H" & srow) = sp.ItemValue("M04")
                    Range("H" & srow).FormulaR1C1 = "=ROUND(RC[-1],9)"
0
Comment
Question by:leezac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Expert Comment

by:aa-denver
ID: 39907208
Excel will automatically round the number displayed up if you change the number of decimal points displayed.   If that is not exactly what you need, then you can use the round function to specify exactly how much to round up, like to the nearest 5, 10, etc.

Here is a link that explains the all this in more detail:

http://office.microsoft.com/en-us/excel-help/round-a-number-HP003056144.aspx
0
 

Author Comment

by:leezac
ID: 39907383
I changed the rounding as you suggesed in the cell,  it shows 0.000000274 but when I click on it is shows 0.000000273985  

There is this formulat that looks at the cell and shows a valued based on the rounding.

  Range("J" & srow).FormulaR1C1 = "=IF(RC[-1]=0,0,IF(RC[-3]=0.000000274,""Check"",IF(RC[-2]>0.000000274,""Valid"",""Check"")))"

I believe because of the 0.000000273985 still being there that the formula for J shows incorrect.  It should say "Valid" but says "Check"
0
 

Author Comment

by:leezac
ID: 39907628
In reference to my last comment.  It may work.  Testing.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:aa-denver
ID: 39907855
If you are printing the spreadsheet, the "display rounding" will be good enough.  If you are wanting to truncate the trailing digits, then you will need to use the round formula.

Removing trailing digits may be important to you.  One place this is commonly needed is in money calculations where the trailing digits can make a column total higher than if they are not there.  Your numbers don't appear to be related to financial totals, but whatever your application, it may not tolerate the trailing digits.

I don't understand your need for using a range.  You could just create a new column, create a formula for the first line and then copy it to all the other lines below.

Here is a simple example.  This example uses only 1 decimal place.  You would need to change the value to 9.   H1 = round(G1,9) instead of H1 = round(G1,1)


http://spreadsheets.about.com/od/excelfunctions/qt/070809_round.htm
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39909682
I see this question still hanging. Did you get your solution ? If not, could you pls post the workbook that have the data together with this code so we can look it up closer ?
gowflow
0
 

Author Comment

by:leezac
ID: 39909965
No.  Is there vba code i can use to loop through Columns G and H to end of row and round to 9 digits ??
0
 

Author Comment

by:leezac
ID: 39909989
Sub test()
    Sheets("Sheet1").Range("G1:H").Select
    Selection.NumberFormat = "0.000000000"
  End Sub

Would something like this work - to just replace the values?
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39910006
No not this way. Please post sample workbook with the data and I will do it for you. Don't give me bits of codes it is not this way.

gowflow
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39910045
Not sure but is this what you want ??

Sub test()
    Sheets("Sheet1").Range(Range("G1"), Range("H" & Rows.Count).End(xlUp)).Select
    Selection.NumberFormat = "0.000000000"
End Sub

Open in new window


gowflow
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
A WS within a WS 11 36
Excel Date Question 8 39
Userform to show a range in excel. 3 24
count number 10 24
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question