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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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