View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bassman62 Bassman62 is offline
external usenet poster
 
Posts: 117
Default Adjusting formulas by copying across cells w/o changing the refere

Jamie,

The following code will add the ROUND function to any formula resulting with
a number within a contiguous range.
Tested but I recommend saving the file before running.
Insert the code into a standard module: press Alt-[F11] to display the VB
editor.
In the left pane, right-click on the file name and select Insert Module
Paste the code into the new module
Modify these two lines to fit your needs:
Set rng = Worksheets("Sheet1").Range("A1:B3")
d = 2 'set number of decimals to round to.
Change the sheet name, range and decimal number as needed. (Leave the
"quotes" in place)
To run the macro from the worksheet, press Alt-[F8] and select "addround"
then click Run.
Again, Save the file before running for there is no undo for this.
To make sure that the code is not run again, delete it from the module or
remove the module. From VB editor right-click on the module and select
"Remove..."

Regards,
Dave
--------------------------------------------------------

Option Explicit

Sub addround()

Dim rng As Range
Dim d As Double
Dim rLoopCell As Range

' Set Your sheet name and contiguous range here
Set rng = Worksheets("Sheet1").Range("A1:B3")
d = 2 'set number of decimals to round to.

On Error Resume Next
For Each rLoopCell In rng
If rLoopCell.HasFormula And IsNumeric(rLoopCell.Value) Then
rLoopCell = "=" & "ROUND(" & Mid(rLoopCell.Formula, 2, 1000) & "," & d &
")"
End If
Next rLoopCell

End Sub


------------------------------------------------------
"Jamie" wrote in message
...
Hello,

I was wondering if the below situation could be made easier:

I have cells that already have a formula in them. The formulas have no
specific pattern. Therefore I can't just adjust one formula and copy that
across because the referenced cells will change. I need to adjust that
formula for all the cells but the reference need to stay the same.

For example: cell A1: =g25*f2 A2: = z1*aa5 A3: =b2/b3

I need to round the answers so I want the cell formulas to look like this:
A1:=round(g25*f2,-2) A2: =round(z1*aa5,-2) etc...

Is there anyway to add the "round" formula, or any formula for that
matter,
to one cell and then copy it to the remaining cells so that just the
"round"
formula is added and all the references stay exactly the same.

Thanks,