加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

VBA多人中随机抽取若干名不重复的人

(2015-10-15 13:11:09)
标签:

excel

vba

分类: ExcelVBA
VBA多人中随机抽取若干名不重复的人
Sub qcw()
    Dim nRow%, arr
    rs = [g1]: xb = [I1]      '人数,性别
    nRow = Range("A65536").End(xlUp).Row
    arr = Range("a1:b" & nRow)
    Range("c1:c" & nRow).Formula = "=rand()"
    If xb = "男" Then
        Range("a1:c" & nRow).Sort key1:=[b1], key2:=[c1], order1:=xlAscending
    ElseIf xb = "女" Then
        Range("a1:c" & nRow).Sort key1:=[b1], key2:=[c1], order1:=xlDescending
    Else
        Range("a1:c" & nRow).Sort key1:=[c1]
    End If
    [c:e].ClearContents
    Range("d1:e" & rs).Value = Range("a1:b" & rs).Value
    Range("a1:b" & nRow) = arr
End Sub

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有