Using a Message Box to display ‘Random Quotation’ stored in cells

R

robertguy

Hi

Can any one help me with this one ?


What I’m trying to do is to click on a button which runs a Macro whic
in turn selects a random quotation i.e. “to be or not to be….” whic
is already stored in a cell.

I have about twenty quotes but I need to added to them all the time s
the list would keep on growing


Any help would be greatly appreciated


Many thanks


Ro
 
F

Frank Kabel

Hi Rob
if your quotes are in column A of the active sheet try the following
code (assign this to a button on the active sheet):
Private Sub CommandButton1_Click()
Dim wks As Worksheet
Dim row_index As Long
Dim lastrow As Long
Set wks = ActiveSheet
lastrow = wks.Cells(Rows.count, "A").End(xlUp).row

row_index = Int(lastrow * Rnd + 1)
MsgBox "Quote:" & wks.Cells(row_index, "A").Value
End Sub
 
Top