Excel automated raffle draw

stevejpearson

Board Regular
Joined
Oct 31, 2009
Messages
64
Hi all,

I know how to randomly select a name from a list in excel but what I would like to do is be able to click a start button in excel that generates a 5-10 second message before announcing the winner i.e Are you ready........and the winner of the Ipod is...........randomly generated name.

Can someone please help?

Thanks

Steve
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
see below.

on your sheet put an ActiveX Control commandbutton from the View\Toolbars\Control Toolbox (please note: this is not the same as a Form control commandbutton). double-click the button and put the following code. Close the vba ide. Then exit 'design view' by clicking the ruler and pencil icon on the Control Toolbox toolbar.

Code:
Private Sub CommandButton1_Click()

UserForm1.Show

End Sub

notice we will be using a userform. so you'll need to hold alt+f11 then insert a userform (Insert then Userform on the vba ide menu bar). Keep the default name 'UserForm1'. Feel free to change the userform caption to whatever you like (currently it will be 'userform1' *same as the userform name) in the properties window (press F4 if you don't see the properties window)

on the userform, put a label (keep the default name 'label1')

double-click the userform and change the code from a 'userform_click' event to below:

Code:
Private Sub UserForm_Activate()
 
Randomize
 
With Label1
    .Font.Bold = True
    .Font.Italic = True
    .Font.Name = "Verdana"
    .Font.Size = 16
    .ForeColor = 255
    .Caption = "Are you ready...?"
End With
 
Application.Wait Now + TimeValue("00:00:05")
DoEvents
 
With Label1
    .Caption = "...and the winner of the Ipod is..."
End With
    
Application.Wait Now + TimeValue("00:00:05")
DoEvents
 
Dim LastRow As Long
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row

With Label1
    .Caption = Sheets("Sheet1").Range("A" & Int((LastRow - 1) * Rnd + 2))
End With

End Sub

Some additional notes. The randomly selected name will be pulled from Sheet1, Column A, starting from row 2 down to the last used range in Column A.

This is just to get you starting. Try experimenting with changing fonts or font colors. Feel free to add some pictures to the Userform. You know...be creative!
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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