Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Identifying the presence of a randomly ordered text string in a cell AG[_3_] Excel Worksheet Functions 2 September 3rd 09 10:21 PM
what can I do to randomly select cells that contain text? gmadden2 Excel Worksheet Functions 2 January 6th 09 05:58 PM
Column picked randomly with probability relative to number of entr Neil Goldwasser Excel Worksheet Functions 4 May 30th 06 08:55 AM
If certain item is picked, then text added... roger_home Excel Discussion (Misc queries) 6 February 12th 06 10:39 PM
i have fields that are formatted for text that randomly convert t. dave glynn Excel Discussion (Misc queries) 2 February 22nd 05 09:03 PM


All times are GMT +1. The time now is 10:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"