|
- Sub GetRoundRow()
- Dim vData As Variant, nRow As Double
- Dim vFill As Variant, nFill As Double
- Dim nGetRow As Double, dicData As Object
-
- Application.ScreenUpdating = False
- nGetRow = Val(InputBox("请输入要随选的行数:"))
- With Sheet1
- .[B:B].ClearContents
- vData = .[A1].CurrentRegion.Value
- If nGetRow > 0 Then
- Set dicData = CreateObject("Scripting.Dictionary")
- ReDim vFill(1 To nGetRow, 1 To 1)
- For nRow = 1 To UBound(vData)
- dicData(nRow) = vData(nRow, 1)
- Next
- Do While nGetRow > 0 And dicData.Count > 0
- nRow = Int(Rnd() * dicData.Count)
- If nRow = dicData.Count Then nRow = nRow - 1
- nFill = nFill + 1
- vFill(nFill, 1) = dicData.Items()(nRow)
- nRow = dicData.Keys()(nRow)
- dicData.Remove nRow
- nGetRow = nGetRow - 1
- Loop
- If nFill > 0 Then .[B1].Resize(nFill) = vFill
- End If
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|