Random an array

whcmelvin

Board Regular
Joined
Jul 27, 2011
Messages
82
hi, i would like to know how to random an array. for example, the array values is burger king, mac and long john sliver. how do i make one of it appear when i click on a button and the values will appear on msg box.the program should random the values. thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Something like this should work. Create your array...

Code:
MyArray = Array("burger king", "mac", "long john sliver")
Then get one at random...

Code:
RandomIndex = Int((UBound(MyArray) - LBound(MyArray) + 1) * Rnd + LBound(MyArray))
MsgBox MyArray(RandomIndex)

Note: The expression I used in the assignment to the RandomIndex variable came from help files for the Rnd function.
 
Upvote 0

Forum statistics

Threads
1,222,313
Messages
6,165,291
Members
451,950
Latest member
WH2000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top