'链接:
https://pan.baidu.com/s/1dFYa4m9 密码:uv4j
Option Explicit
Dim username, cnt, lmt, mark
Private Sub CommandButton3_Click()
Dim i, t, n
Randomize
For i = 1 To UBound(username, 1)
n = Int(Rnd * UBound(username, 1)) + 1
t = username(i, 1): username(i, 1) = username(n, 1): username(n, 1) = t
t = username(i, 2): username(i, 2) = username(n, 2): username(n, 2) = t
Next
If OptionButton1.Value Then n = 1
If OptionButton2.Value Then n = 2
If OptionButton3.Value Then n = 3
If cnt(n) = lmt(n - 1) Then MsgBox mark(n - 1) & "已抽完!": Exit Sub
cnt(n) = cnt(n) + 1
For i = 1 To UBound(username)
If Len(username(i, 1)) > 0 Then
username(i, 1) = vbNullString
TextBox1 = TextBox1 & vbNewLine & Format(cnt(n), "第0个" & mark(n - 1)) & username(i, 2)
Exit For
End If
Next
End Sub
Private Sub UserForm_Activate()
Dim n
With Sheets("名单")
username = .Range("a2:b" & .Cells(Rows.Count, "a").End(xlUp).Row)
End With
ReDim cnt(1 To 3) As Long
lmt = Array(3, 10, 20)
mark = Split("一等奖 二等奖 三等奖")
OptionButton3.Value = True
n = lmt(0) + lmt(1) + lmt(2)
If UBound(username, 1) < n Then MsgBox "参加的人数太少!" & vbNewLine & "当前人数:" & _
UBound(username, 1) & vbNewLine & "最少人数:" & n
End Sub