![]() |
Display text at random
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 |
Display text at random
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 |
Display text at random
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 |
All times are GMT +1. The time now is 06:19 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com