|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub ToggleButton1_Click()
Set d = CreateObject("Scripting.Dictionary")
arr = Sheets("花名册").Range("a1", Sheets("花名册").Cells(Rows.Count, 1).End(xlUp))
For i = 1 To UBound(arr)
d(arr(i, 1)) = ""
Next i
arr = Sheets("抽奖").Range("K1", Sheets("抽奖").Cells(Rows.Count, "K").End(xlUp))
For i = 2 To UBound(arr)
If d.EXISTS(arr(i, 1)) Then d.Remove (arr(i, 1))
Next i
If d.Count = 0 Then
MsgBox "无抽奖人员!"
Exit Sub
End If
If ToggleButton1.Value = True Then
ToggleButton1.Caption = "暂停"
Do
n = Int((d.Count - 1 + 1) * Rnd + 1)
Sheets("抽奖").Range("a1") = Application.WorksheetFunction.Index(d.keys, n)
DoEvents
Loop Until ToggleButton1.Value = False
Else
ToggleButton1.Caption = "开始"
Sheets("抽奖").Cells(Rows.Count, "k").End(xlUp).Offset(1, 0) = Sheets("抽奖").Range("a1")
r = Sheets("抽奖").Range("a1")
d.Remove (r)
End If
End Sub
|
|