Msgbox with randomly picked text

C

Cajeto 63

Hello everybody,

I would like to create a message box with random message picked from a list
preset in the cells of the workbook itself. May be the example below will be
more clear:

On sheet2:
Cell A1= blablabla
cell A2= totototo
cell A3= yepyepyep

Then the message box would give either the text in A1 or A2 or A3.

As my knowledge in VBA is quite limited it would be very nice if one of you
could give me a hand.

Thank you.
 
T

Tom Ogilvy

sub ABC()
set rng = Range("A1:A3")
i = int(rnd()*rng.count + 1)
msgbox rng(i)
End Sub
 
C

Cajeto 63

Wonderful Tom,
It's simple, I can understand it, and it works.

Thank you very much for you help.
 
J

Jean-Yves

Hi,

Sub test()
Dim nt As Integer
Randomize 'to initialize the random-number generator
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound) 'from help
nt = Int((3 - 1 + 1) * Rnd + 1)
MsgBox worksheets(2).Range("A" & nt)
End Sub
Regards
Jean-Yves
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top