Private Sub CommandButton1_Click()
Dim I As Long, Arr() As Long, S As Long
Randomize
ReDim Arr(1 To 11)
For I = 1 To 11 '初始化
Arr(I) = I
Next
For I = 1 To 7
S = Int(Rnd() * UBound(Arr) + 1) '产生随机数
Range("A" & I).Value = Arr(S)
Arr(S) = Arr(UBound(Arr)) '将产生的随机数和数组最后一个元素交换
If UBound(Arr) = 1 Then Exit For '如果只有一个元素 退出
ReDim Preserve Arr(1 To UBound(Arr) - 1) '将数组最后一个元素剔除
Next
End Sub
似乎下载一个excle抽奖程序就可以解决这个问题的吧。试试吧。