我为你写了一个自定义函数,请试下。代码如下:
Function Myrand(PartAre As Range, Part As String) As String
'PartAre 部门所在区域;
'Part 你期望抽查的部门,可以是字符,也可以是单元格
'eg: =Myrand($A$1:$A$8,"ENG") 或者 =Myrand($A$1:$A$8,A3)
partnum = 0
For Each m In PartAre
tmpStr = mText
If UCase(tmpStr) = UCase(Part) Then partnum = partnum + 1
Next m
randnum = Int(partnum Rnd()) + 1
partnum = 0
For Each m In PartAre
tmpStr = mText
If UCase(tmpStr) = UCase(Part) Then
partnum = partnum + 1
If partnum = randnum Then Exit For
End If
Next m
Myrand = Cells(mRow(), mColumn() + 1)Text
End Function
用法:
部门在A1~A8,人员在B1~B8(函数自动从部门后一列取人员),则在其他单元格中输入公式:
=Myrand($A$1:$A$8,"ENG") 或者 =Myrand($A$1:$A$8,A3)
注:A3中的所填写的内容为 ENG
不清楚可以Hi我。
GoodLuck!
Sub PickSomebody()
Dim class As Range
Set class = Range("A2", Range("A2")End(xlDown))
n = classRowsCount
' get a random seed first,to get the random number
Randomize
s = (Int(n Rnd + 1))
MsgBox class(s)
Cells(s + 1, 1)Select
End Sub
以上就是关于在EXCEL中如何用VB做一个随机点名系统全部的内容,包括:在EXCEL中如何用VB做一个随机点名系统、用Excel随机点名程序,能否自动定位到被点中的那一项上、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)