|
- Sub qs()
- Dim arr, i, j, x, dic, temp
- Set dic = CreateObject("scripting.dictionary")
- drr = Sheets("条件").Range("b3:q3").Value
- With Sheet1
- For col = 1 To UBound(drr, 2)
- If drr(1, col) <> Empty Then
- rw = .Cells(Rows.Count, col).End(3).Row
- brr = .Range(Cells(3, col), Cells(rw, col)).Value
- x = UBound(brr)
- ReDim arr(1 To x)
- For i = 1 To x ' 初始化数组
- arr(i) = i
- Next i
- For i = 1 To x ' 随机排列数组
- j = i + Int((x - i + 1) * Rnd)
- temp = arr(i) ' 交换元素
- arr(i) = arr(j)
- arr(j) = temp
- Next i
- dic.RemoveAll
- For i = 1 To UBound(arr)
- dic(arr(i)) = brr(i, 1)
- Next
- ReDim Err(1 To drr(1, col), 1 To 1)
- For w = 1 To drr(1, col)
- Err(w, 1) = dic(w)
- Next
- With Sheets("抽取")
- .Cells(3, col).Resize(10000, 1) = ""
- .Cells(3, col).Resize(drr(1, col), 1) = Err
- End With
- End If
- Next
- End With
- Sheets("抽取").Select
- End Sub
复制代码 |
|