作者:乔山办公网日期:
返回目录:office365
用VBA代码(我设百置的抽签1-100,不会有重复度),如下:Subcq()Range("c3:e3").ClearContentsDimiAsBytei=3T1:DoWhilei<6 IfCells(3,i)=""Then Cells(3,i)=Application.RandBetween(1,100) EndIf i=i+1LoopIfApplication.Or(Cells(3,3)=Cells(3,4),Cells(3,3)=Cells(3,5),Cells(3,4)=Cells(3,5))Then Range("c3:e3").ClearContents GoToT1EndIfEndSub效果内如下(若图片没有动容画,请点一下图片)
用VBA代码(我设置的复抽签1-100,不会有制重复),如下:
Sub cq()
Range("c3:e3").ClearContents
Dim i As Byte
i = 3
T1:
Do While i < 6
If Cells(3, i) = "" Then
Cells(3, i) = Application.RandBetween(1, 100)
End If
i = i + 1
Loop
If Application.Or(Cells(3, 3) = Cells(3, 4), Cells(3, 3) = Cells(3, 5), Cells(3, 4) = Cells(3, 5)) Then
Range("c3:e3").ClearContents
GoTo T1
End If
End Sub
效果如下(若知图片没有动道画,请点一下图片)
你需要再加一个初始化按钮,代码如下(commandbutton1就是你的next,commandbutton2是初始化按钮)
Dim arr(), count
Private Sub CommandButton1_Click()
If count <= 29 Then
n = Int(Rnd * (UBound(arr) - LBound(arr) + 1)) + LBound(arr)
TextBox1.Text = arr(n)
Cells(count + 1, 10) = arr(n) '测试代码可删除
Cells(count + 1, 11) = n '测试代码可删除
count = count + 1
arr(n) = arr(UBound(arr))
If UBound(arr) > 1 Then ReDim Preserve arr(1 To UBound(arr) - 1)
Else
MsgBox "所有人员都已抽完e69da5e887aae79fa5e98193364"
End If
End Sub
Private Sub CommandButton2_Click()
ReDim arr(1 To 30)
Randomize
TextBox1.Text = ""
For i = 1 To 30
arr(i) = Cells(i, 1)
Next
MsgBox "已初始化"
count = 0
End Sub
1到15号每次需抽几个号?抽取过的号下次还参与抽号吗?描述不是清楚。