打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VBA自定义函数2

'参数不定的自定义函数

Function cheng(ParamArray n())

Dim num, k

k = 0

For Each num In n

k = k + num

Next num

cheng = k

End Function



'参数值默认和参数缺省


Function shuiji1(maxnum, geshu, Optional qo As Integer)

Dim d As New Dictionary

Dim num

Application.Volatile

Do

num = Int(Rnd() * maxnum + 1)

If qo = 0 Then

d(num) = ''

ElseIf qo = 2 Then

If num Mod 2 = 0 Then d(num) = ''

ElseIf qo = 1 Then

If Not num Mod 2 = 0 Then d(num) = ''

End If

Loop Until d.Count = geshu

shuiji1 = Application.Transpose(d.Keys)

End Function


Function shuiji2(maxnum, geshu, Optional qo As Integer = 2)

Dim d As New Dictionary

Dim num, m

Application.Volatile

m = 1

Do

num = Int(Rnd() * maxnum + 1)

If qo = 2 Then

If num Mod 2 = 0 Then d(num) = ''

ElseIf qo = 1 Then

If Not num Mod 2 = 0 Then d(num) = ''

Else

Exit Function

End If

Loop Until d.Count = geshu

shuiji2 = Application.Transpose(d.Keys)

End Function



'返回一个固定区间固定个数的不重复随数

Function shuiji(maxnum, geshu) 'maxnum是区间最大的数,geshu是返回多少个不重复的数

Dim d As New Dictionary

Dim num

Application.Volatile

Do

num = Int(Rnd() * maxnum + 1)

d(num) = ''

Loop Until d.Count = geshu

shuiji = Application.Transpose(d.Keys)

End Function


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VBA自定义函数集锦
VBA基础入门(49)35选7该怎么选?(2)
Excel取唯一值的五种方法
VBA 释放内存
excel-vba应用示例之创建新的工作簿
透视表批量修改汇总字段
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服