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
 

crimson_b1ade

Well-known Member
Joined
Sep 27, 2008
Messages
1,557
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!
 

Forum statistics

Threads
1,081,513
Messages
5,359,226
Members
400,521
Latest member
smarty1995

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top