|
楼主 |
发表于 2014-7-14 09:24
|
显示全部楼层
ghostjiao 发表于 2014-7-12 19:25
随机生成选择数据
你好,这个符合我的要求,能否加下注释,学习一下,谢谢!- Sub 分组()
- Dim arr, i%, j%, k%, brr(1 To 100, 1 To 8), temp, RndNum%, n%
- arr = Sheet1.Range("A1").CurrentRegion
- If UBound(arr) Mod 8 = 0 Then n = UBound(arr) \ 8 Else n = UBound(arr) \ 8 + 1
- VBA.Randomize
- For i = 1 To n
- For j = 8 To 1 Step -1
- k = k + 1
- If k <= UBound(arr) Then
- RndNum = Int(Rnd * (UBound(arr) - k + 1)) + 1
- brr(i, j) = arr(RndNum, 1)
- temp = arr(RndNum, 1)
- arr(RndNum, 1) = arr(UBound(arr) - k + 1, 1)
- arr(UBound(arr) - k + 1, 1) = temp
- End If
- Next
- Next
- Range("C1").Resize(n, 8) = brr
- End Sub
复制代码 |
|