当前位置:文档之家› 用excel实现随机抽签

用excel实现随机抽签

用excel实现随机抽签
先看看程序运行情况:将数据复制粘贴进去,点开始开始生成数据,停止产生结果。

实现代码
''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 程序制作:江西生物科技职业学院'
' 真随风'
' 2011-10-18 '
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim i, j, k As Integer
Dim Flag As Boolean
Dim str$
Sub 按钮1_Click()
Flag = False
If Cells(1, 1) = "准备就绪" Then
Cells(1, 1) = "正在生成"
Do Until Flag
Call dornd
DoEvents
Loop
End If
End Sub
Sub dornd()
i = getcell
For j = 1 To i
Cells(j + 2, 1) = ""
Next
j = 1
Do Until j > i Or j = 10000
k = Int(Rnd(j / 10) * (i) * 10)
If k < i And Cells(k + 3, 1) = "" Then
Cells(k + 3, 1) = j
j = j + 1
End If
Loop
End Sub
Function getcell()
i = 3
Do While (Cells(i, 2)) <> ""
i = i + 1
Loop
getcell = i - 3
End Function
Sub 按钮11_Click()
Cells(1, 1) = "准备就绪"
Flag = True
MsgBox ("已确定随机顺序")
str = "A2:Z" & getcell + 2 & ""
Range(str).Select
'excel 2003
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
'excel 2007
'ActiveWindow.SmallScroll Down:=-18
'ActiveWorkbook.Worksheets("excel程序随机抽签").Sort.SortFields.Clear
'ActiveWorkbook.Worksheets("excel程序随机抽签").Sort.SortFields.Add Key:=Range("A2") _
' , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
'With ActiveWorkbook.Worksheets("excel程序随机抽签").Sort
' .SetRange Range(str)
' .Header = xlYes
' .MatchCase = False
' .Orientation = xlTopToBottom
' .SortMethod = xlPinYin
' .Apply
'End With
End Sub
Sub Macro1()
'
' Macro1 Macro
' 宏由微软中国录制,时间: 2011-10-19
'
'
Range("F14:J20").Select
Selection.Sort Key1:=Range("F14"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
End Sub
不用你自己编写了,下载吧。

相关主题