Display text at random

  • Thread starter Thread starter Markv
  • Start date Start date
M

Markv

Hi all...

Can anyone please post a detailed way of how I can display text lines at
random
in a specific cell when I press a macro button.
The text is pre-typed in the module I would assume. Also how can I set all
this up to work together?
It would a great help if anyone can assist.

Thanks
 
I can actually field this, so here's my take:

Create an array with all your values. Then create a random number,
and that number refers to one of the entries in your array.
If you input the code below into a module, it should work and you can
tweak it as you need be.

Since, NP

------------------------------

Sub RandomLines()

Dim RandomLinesArray(0 To 4) As Variant
Dim RandomNumber As Long

RandomLinesArray(0) = "ZERO"
RandomLinesArray(1) = "ONE"
RandomLinesArray(2) = "TWO"
RandomLinesArray(3) = "THREE"
RandomLinesArray(4) = "FOUR"

RandomNumber = Int((5 - 1 + 1) * Rnd + 1) - 1

Sheets("Sheet1").Range("A1").Value = RandomNumber
Sheets("Sheet1").Range("A2").Value = RandomLinesArray(RandomNumber)

End Sub
 
Back
Top