|
'先运行“模拟数据”,然后再抽奖
'循环6次后重新开始
Option Explicit
Dim data, num As Long
Sub 抽奖()
Dim i, j, k, m, n, t
If num = 0 Then
data = Range("a2:d" & Cells(Rows.Count, "a").End(xlUp).Row)
Randomize
For i = 1 To UBound(data, 1)
n = Int(UBound(data, 1) * Rnd) + 1
For j = 1 To UBound(data, 2)
t = data(i, j): data(i, j) = data(n, j): data(n, j) = t
Next
Next
[f:f].Resize(, (UBound(data, 2) + 1) * 6).ClearContents
End If
ReDim arr(1 To 50, 1 To UBound(data, 2))
num = num + 1: n = 0
For i = 50 * num - 49 To 50 * num
n = n + 1
For j = 1 To UBound(data, 2)
arr(n, j) = data(i, j)
Next j, i
With [f2]
.Offset(, (num - 1) * (UBound(data, 2) + 1)).Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End With
If num = 6 Then num = 0
End Sub
Sub 模拟数据()
Dim i
ReDim arr(1 To 3000, 1 To 4)
For i = 1 To UBound(arr, 1)
arr(i, 1) = i: arr(i, 3) = 10 ^ 4 + i
arr(i, 2) = "aa": arr(i, 4) = "bb"
Next
With [a1]
.Resize(, 4) = Split("序号 部门 工号 姓名")
.Offset(1).Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End With
End Sub |
|