i've got a table with a lot of diffrent formulas and i'd like to round numbers to 0.05 or 0.00. how can i do that in one step without having to put the formula in each cell?
This could be done with code but over the years I have learned that the quickest and simplest way, once you've done it a couple of time is the following.
Replace all the "=" with "#=" to turn the formulae into text and then create a copy of the sheet and in the copy of the table put the formulae "="=MROUND("&MID(OriginalSheet!CellREF,3,1000)&",0.05)into each cell where CellREF is the range of the corresponding cell in the original sheet and then copy the range and paste as values into the original sheet where they will appear as text. Finally, on the original sheet do a search and replace all "#=" with "=" and then another search and replace all "=" with "=" (yes that is right) and the formulae will be converted back into formulae. Then simply delete the copy sheet.
It sounds complicated but is actually very quick to do (literally less than two minutes, and is a useful cheat technique).
(This method using the "#=" and the MID function will get around any conditions in functions using the "=" sign.)
Hasit's option might be suitable, depending on whether you want the extra column(s) of formulas.
My understanding is that you want to modify your existing formulas to include the ROUND function - WITHOUT having to manually edit each and every formula.
If this is the case, then the following VBA code should be simple enough and flexible enough to make your task easy and fairly quick.
I have created two separate routines, which you should attach keyboard shortcuts to - for example attach <Control> Q to the routine for rounding to 2 decimal places, and <Control> W for rounding to zero decimal places.
The code includes a line which takes the cursor down to the next row each time you activate it, so it will be a matter of repeatedly using <Control> Q, for example, until you reach the end of the formulas which you want to add the ROUND function with 2 decimal places. Or, you can alternate from one to the other where necessary.
Here's the code...
Dim frm As String
Sub Rnd_2()
frm = ActiveCell.Formula
frm = Mid(frm, 2, 999)
frm = "=Round(" & frm & ",2)"
ActiveCell.Formula = frm
Selection.NumberFormat = "0.00_);(0.00)"
ActiveCell.Offset(1, 0).Select
End Sub
Sub Rnd_0()
frm = ActiveCell.Formula
frm = Mid(frm, 2, 999)
frm = "=Round(" & frm & ",0)"
ActiveCell.Formula = frm
Selection.NumberFormat = "0.00_);(0.00)"
ActiveCell.Offset(1, 0).Select
End Sub
Please advise as to how you make out, or whether you
require any further assistance.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.