Replace part of a formula with its calculated value

howerd

New Member
Joined
Dec 24, 2009
Messages
44
Hi - I am looking to replace part of a formula with its calculated value for a number of different cells.

I know how to do this manually, however I have a number of cells, so I wondered if there is a quicker way to replace multiple cells?

The formula includes rand() which is generating a number between 0 and 1, however I don't want it to re-calculate every time.

As an example all of the cells have part of the formula as following:

NORMINV(RAND(),$B$3,$B$4)

and I want the calculated value for rand() to be showing in each cell instead, like this:

NORMINV(0.1645148,$B$3,$B$4)

Any help on how to do this over multiple cells would be gratefully received.

Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You'd have to recalculate a new Rand() value at each replacement - would that be acceptable?
 
Upvote 0
Hi RoryA,

Thanks for getting back to me.

Yes, so I am looking for each cell to have a different random number in.

Thanks
 
Upvote 0
You could do something like this then:

VBA Code:
Sub UpdateRandFormulas()
   Dim formulaRange As Range
   On Error Resume Next
   Set formulaRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
   On Error GoTo 0
   
   If Not formulaRange Is Nothing Then
      Application.Calculation = xlCalculationManual
      Dim cell As Range
      For Each cell In formulaRange.Cells
         If InStr(1, cell.Formula, "RAND()") <> 0 Then
            cell.Formula = Replace$(cell.Formula, "RAND()", Rnd)
         End If
      Next cell
      Application.Calculation = xlCalculationAutomatic
   End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,461
Messages
6,124,954
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top