|
男、女同时抽取时:
Option Explicit
Public xx As Boolean
Public yy As Boolean
Private Sub CommandButton1_Click()
Dim a As Collection, b As Collection, j&, m&, n&, jj&, mm&, nn&
If CommandButton1.Caption = "抽取开始" Then
CommandButton1.Caption = "抽取停止"
xx = True
yy = True
Do While xx = True Or yy = True
Set a = New Collection
Set b = New Collection
For m = 2 To 101
If Cells(m, 3) = "男" Then
a.Add m
End If
Next m
For j = 2 To 31
n = Int(Rnd * a.Count) + 1
Cells(j, 4) = Cells(a(n), 2)
a.Remove (n)
Next
For mm = 2 To 101
If Cells(mm, 3) = "女" Then
b.Add mm
End If
Next mm
For jj = 2 To 21
nn = Int(Rnd * b.Count) + 1
Cells(jj, 5) = Cells(b(nn), 2)
b.Remove (nn)
Next
DoEvents
Loop
Else
CommandButton1.Caption = "抽取开始"
xx = False
yy = False
End If
End Sub
|
评分
-
1
查看全部评分
-
|