Thread: Random time?
View Single Post
  #3   Report Post  
slipper slipper is offline
Junior Member
 
Posts: 8
Default

Quote:
Originally Posted by joeu2004[_2_] View Post
"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.

Thanks for your reply, to make things a little clearer i have a cell displaying a random message selected from a list, this part all works fine.

However for several of the messages i want them hidden from the user for a random time (0-15 minutes).

I can hide the message from the user by originally filling the cell black which effectivley hides the message, the problem is how to clear this formatting after the random time has elapsed.

I am familiar with conditional formatting and how to use it but cannot find a function that does what i need.

Is there any fuction that would do as i ask? Excuse my coding in my earlier post it was just my way of making my point clearer and not meant as actual code.

If this can be done by Excel formulas that would be great, if it needs VBA coding i would need a walkthrough as i have not used it before.


The line of code you posted

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

would that work in conditional formatting as a new rule?

Thanks for any help


slipper