|
我也写了一个,今天闲着着没事
- Option Explicit
- Sub test()
- Dim Dic, arr1, L, x, Dic1, L1, arr2, 变, z, arr3, Dic2
- Set Dic = CreateObject("Scripting.Dictionary")
- Set Dic1 = CreateObject("Scripting.Dictionary")
- Set Dic2 = CreateObject("Scripting.Dictionary")
- '========================================
- On Error Resume Next
- L = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
- arr1 = Sheets(2).Range("A2:A" & L)
- For x = 1 To UBound(arr1)
- Dic(arr1(x, 1)) = ""
- Next x
- Sheets(2).[A2:A10000].ClearContents
- Sheets(2).[A2].Resize(Dic.Count, 1) = Application.Transpose(Dic.keys)
- '以上代码是防止重名
- '================================
- L1 = Cells(Rows.Count, 4).End(xlUp).Row
- arr2 = Range("D1:D" & L1).Value
- For x = 2 To UBound(arr2)
- Dic1(arr2(x, 1)) = ""
- Next x
- L = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
- arr1 = Sheets(2).Range("A2:A" & L)
- For x = 1 To UBound(arr1)
- If Not Dic1.exists(arr1(x, 1)) Then
- Dic2(arr1(x, 1)) = ""
- End If
- Next x
- arr3 = Dic2.keys
- For z = 1 To 1800
- 变 = Application.WorksheetFunction.RandBetween(1, Dic2.Count)
- Cells(2, 2) = arr3(变 - 1)
- Next z
- L1 = Cells(Rows.Count, 4).End(xlUp).Row
- If L1 = L Then MsgBox "全部抽完": End
- Cells(L1 + 1, 3) = "第" & L1 & "名"
- Cells(L1 + 1, 4) = Cells(2, 2)
- End Sub
- Sub 重新抽奖()
- Range("C2:D10000").ClearContents
- Range("B2:B9").ClearContents
- End Sub
复制代码 |
|