Random Generator

matthewjapp

Board Regular
Joined
May 14, 2007
Messages
115
Hi there,

I have a sheet with a ranbetween function (1-5) and to update the function (not sure why, I am sure there's a better way to do it) I use a text to columns macro which seems to refresh the formula - great.
Only problem is that there is a whole load of code which runs after the event which also seems to change the random number. Is there any way to only change the random number once?

Thanks,

Matthew
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try inserting code along the lines of
Code:
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues

obviously you'll have to select the relevant range first but that should stop any more random numbers being generated.
 
Upvote 0
You can switch calculations to manual in tools->options.

The code for the two things mentioned is

Code:
Application.Calculation = xlCalculationManual
Application.EnableEvents = False

But if you're going to code why not make it easier and use VBA to generate stable, random numbers that don't change anyway? You can overwrite them at will by rerunning the code anyway

cell value = int(Rnd*5)+1 generates a random number between 1 and 5...
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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