Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 On 725, ȫ3:39, Markv wrote: 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 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
thanks a lot for your patient reply..I will give it a go.
"pallaver" wrote: 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 On 7月25日, 午後3:39, Markv wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Random select of text | Excel Worksheet Functions | |||
Random Text selection Q | Excel Worksheet Functions | |||
Random sort function for text | Excel Worksheet Functions | |||
Random selection of text cells | Excel Discussion (Misc queries) | |||
random number with text | Excel Worksheet Functions |