Thread: Random time?
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Random time?

"slipper" wrote:
I want a random time to be generated between 0 and 15 minutes,
and for this to be added to time now, when this new time is
reached i would like the contents of a cell to be displayed.

So something like
new time = NOW() + RANDBETWEEN(0,15) ------ store value
when time = new time(stored value) then display cell contents


Display how? Display which cell contents?

RANDBETWEEN() is an Excel function. Are you writing an Excel formula or VBA
code?

In Excel:

=NOW() + TIME(0,RANDBETWEEN(0,15),0)

But that is not too useful for your purposes, as I understand them
(vaguely).

In VBA:

Dim newTime As Double
Static didRandomize As Boolean
If Not didRandomize Then Randomize : didRandomized = True

newTime = Now() + TimeSerial(0,Int(16*Rnd()),0) ' note: 16, not 15
or
newTime = Now() + TimeSerial(0,Evaluate("randbetween(0,15)"),0)

Application.OnTime newTime,"mySub"

What you do in "mySub" depends on the answers to my questions.