In Excel How Do I Random a Number but Not when it recalculates?

T

TxcPhtm

I am trying to make a Macro that will select a few cells and random number
between 1-100 (I have done this). But when I use =RANDBETWEEN(1,100) whenever
I change a number in my cells it randoms. I was wondering whether there was a
=random that doesnt do after every recalculate. Or a Macro term.
 
J

JP

Why not just paste in the value after you use the formula? I believe
all of the random functions (RAND, etc) are volatile.

HTH,
JP
 
J

joeu2004

I am trying to make a Macro that will select a few cells and
random number between 1-100 (I have done this). But when
I use =RANDBETWEEN(1,100) whenever I change a number
in my cells it randoms. I was wondering whether there was a
=random that doesnt do after every recalculate. Or a Macro term.

I am a little confused. On the one hand, you say are "trying to make"
a macro that does this; on the other hand, you say you are using
=RANDBETWEEN(1,100), presumably in an Excel cell. Moreover, you say
that "a macro" will select a few cells. Usually, you select the
cells, then execute a macro to operate on the selected cells.
(Although, of course, you can indeed write the macro so that it makes
the selection.)

Be that as it may, you might be able to accomplish your task (whatever
that is) by computing the random number(s) within the macro. In Excel
2007, you might be able to use WorkSheetFunction.Randbetween, since I
believe the RANDBETWEEN() is now a standard Excel function. I don't
know; I cannot do that in Excel 2003. Alternatively, you can write
your own function, namely:

Function myRandBetween(low As Long, high As Long) As Long
myrandbetween = low + Int((high - low + 1) * Rnd())
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top