ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Msgbox with randomly picked text (https://www.excelbanter.com/excel-programming/375186-msgbox-randomly-picked-text.html)

Cajeto 63

Msgbox with randomly picked text
 
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.

Tom Ogilvy

Msgbox with randomly picked text
 
sub ABC()
set rng = Range("A1:A3")
i = int(rnd()*rng.count + 1)
msgbox rng(i)
End Sub

--
Regards,
Tom Ogilvy


"Cajeto 63" wrote:

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.


Cajeto 63

Msgbox with randomly picked text
 
Wonderful Tom,
It's simple, I can understand it, and it works.

Thank you very much for you help.

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Cajeto 63" wrote:

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.


Jean-Yves[_2_]

Msgbox with randomly picked text
 
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
"Cajeto 63" wrote in message
...
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.





All times are GMT +1. The time now is 11:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com