View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default In Excel How Do I Random a Number but Not when it recalculates?

On Feb 27, 1:56*pm, TxcPhtm wrote:
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