Hello!
I am hoping that you can help me. I am brand new to VBA (as in, I just learned about it yesterday!) but I am trying to develop a spreadsheet that I can use for a raffle.
The idea behind it is that there will be approximately 100 prizes, and 100 raffle tickets drawn. When a ticket is drawn, the winner will have 20 minutes to claim their prize or it is forfeited.
In the Excel spreadsheet, I need to have a row for each prize, along with a countdown timer, and Start, Stop, and Reset buttons. I have gotten the countdown timer and buttons to work for the first row, but how can I repeat this for each additional row, so that I don't have to have 100 copies of the functions that I have written?
Here are my functions:
Sub Countup()
Dim CountDown As Date
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Realcount"
End Sub
Sub Realcount()
Dim count As Range
Set count = [E4]
count.Value = count.Value - TimeSerial(0, 0, 1)
If count <= 0 Then
count.Font.Color = RGB(255, 0, 0)
count.Font.Bold = True
Exit Sub
End If
Call Countup
End Sub
Private Sub Start_Click()
Call Countup
End Sub
Private Sub Reset_Click()
If Cells(5, 4) <> 0 Then
Application.OnTime Now + TimeValue("00:00:01"), "Realcount", , False
Range("E4").Value = "0:20:00"
Range("E4").Font.Color = RGB(0, 0, 0)
Range("E4").Font.Bold = False
Else
Range("E4").Value = "0:20:00"
Range("E4").Font.Color = RGB(0, 0, 0)
Range("E4").Font.Bold = False
End If
End Sub
Private Sub StopButton_Click()
Application.OnTime Now + TimeValue("00:00:01"), "Realcount", , False
End Sub
I am also attaching the current xlsm file, in case that helps. Thank you so much!
Bookmarks