|
Sub 横排模式()
Dim arr As Variant
Dim br()
arr = Range("a1").CurrentRegion
Set dic = CreateObject("scripting.dictionary")
j = Cells(Rows.Count, 1).End(xlUp).Row - 1
k = InputBox("请输入生成的组数", "组数", "5")
If k * 5 > j Then MsgBox "不足以生成" & k & "组,请重新输入": End
ReDim br(1 To k, 1 To 5)
For i = 1 To k
n = n + 1: y = 0
Do
sjs = Application.RandBetween(2, UBound(arr))
If Not dic.exists(sjs) Then
y = y + 1
If y > 5 Then GoTo 10
br(n, y) = arr(sjs, 1)
dic(sjs) = ""
End If
Loop
10:
Next i
[d1].Resize(n, 5) = br
MsgBox "ok!"
End Sub
Sub 竖排模式()
Dim arr As Variant
Dim br()
arr = Range("a1").CurrentRegion
Set dic = CreateObject("scripting.dictionary")
j = Cells(Rows.Count, 1).End(xlUp).Row - 1
k = InputBox("请输入生成的组数", "组数", "5")
If k * 5 > j Then MsgBox "不足以生成" & k & "组,请重新输入": End
ReDim br(1 To k * 5 + k, 1 To 1)
For i = 1 To k
y = 0
Do
sjs = Application.RandBetween(2, UBound(arr))
If Not dic.exists(sjs) Then
y = y + 1
If y > 5 Then GoTo 10
n = n + 1
br(n, 1) = arr(sjs, 1)
dic(sjs) = ""
End If
Loop
10:
n = n + 1
Next i
[m1].Resize(n, 1) = br
MsgBox "ok!"
End Sub
|
|