|
Sub test1()
Dim brr(1 To 6) As String
Dim d As Dictionary
arr = Range("B1:c" & Cells(Rows.Count, 1).End(xlUp).Row).Value '赋值盒号所在列非空行的值给数组arr
u = UBound(arr) '数组arr的个数u
Set d = CreateObject("scripting.dictionary") '建立字典
' Set d = New Dictionary
For i = 2 To u
d(i) = arr(i, 1) & "-" & arr(i, 2)
Next i
a = d.Count
For i = 1 To Int(a / 6)
For j = 1 To 6
str1 = d.Keys
b = Application.WorksheetFunction.RandBetween(1, UBound(str1))
brr(j) = d(str1(b - 1))
d.Remove (str1(b - 1))
a = d.Count
Debug.Print "第" & i & "批", j, brr(j)
Next j
Next i
'余下部分
str1 = d.Items
For i = 0 To UBound(str1)
brr(i + 1) = str1(i)
Debug.Print "第" & Int((UBound(arr) - 1) / 6) + 1 & "批", i + 1, brr(i + 1)
Next i
End Sub
|
|