|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
短信收到,请测试:- Sub Macro1()
- Dim arr(1 To 2), brr(), i&, j&, m&, n&, r&, l&, d As Object, ds As Object
- Set d = CreateObject("scripting.dictionary")
- Set ds = CreateObject("scripting.dictionary")
- m = [d:d].Find("女", , , xlWhole).Row
- arr(1) = Range("a2:d" & m - 1)
- arr(2) = Range("a" & m & ":d" & [a65536].End(3).Row)
- Columns("G:J").ClearContents
- [g1:j1] = Array("宿舍号", "姓名", "学校", "性别")
- For l = 1 To 2
- For i = 1 To UBound(arr(l))
- ds(i) = ""
- Next
- ReDim brr(1 To UBound(arr(l)), 1 To 4)
- lr = UBound(arr(l))
- r = 0
- For i = 1 To WorksheetFunction.RoundUp(lr / 6, 0) - 1
- Do
- n = Int((lr * Rnd) + 1)
- If Len(arr(l)(n, 3)) Then
- If Not d.Exists(arr(l)(n, 3)) Then
- r = r + 1
- d(arr(l)(n, 3)) = ""
- brr(r, 1) = i
- For j = 2 To 4
- brr(r, j) = arr(l)(n, j)
- Next
- arr(l)(n, 3) = ""
- ds.Remove (n)
- End If
- End If
- Loop Until d.Count = 6
- d.RemoveAll
- Next
- k = ds.keys
- m = i
- For i = 0 To ds.Count - 1
- r = r + 1
- brr(r, 1) = m
- For j = 2 To 4
- brr(r, j) = arr(l)(k(i), j)
- Next
- Next
- [g65536].End(3).Offset(1).Resize(lr, 4) = brr
- ds.RemoveAll
- Next
- End Sub
复制代码 |
|