Excel vba随机函数用法和实例
时间:2022-12-01 14:22:30
本文介绍vb随机函数中的Rnd函数,并配合取整函数int来介绍vb随机函数的使用过程。
第一,vb随机函数介绍
Rnd 函数是vb随机函数。
Rnd 函数的作用是返回小于 1 但大于或等于 0 的值。比如0.871445835、0.056236863这样的随机小数。
第二,vb随机函数实例介绍
1.比如要在A1单元格生成一个这样的随机小数,可以这样写代码:
Sub 随机数()
[A1] = Rnd
End Sub
2.又比如要生成20以内的随机数,可以这样写:
Sub 随机数()
[A1] = Int(Rnd * 20)
End Sub
总结:RND是vb随机函数,可以取到的数在0~1之间不包括1, =INT(RND*10)可以是0~9的整数。
3. 如何使用vb随机函数产生两个数字之间的任意数字?比如生成28到95之间的随机整数。可以这样写:
Sub 随机数()
[A1] = Int(67 * Rnd + 28)
End Sub
或者是:
Sub 随机数()
[A1] = Int(Rnd * (67 + 1) + 28)
End Sub
vb随机函数产生两个数字之间的任意数字可以套用这样的格式来写:
rnd *(大数-小数+1)+小数或(大数-小数)* rnd+小数。
文章介绍的是最基础的vb随机函数知识,希望对初学者有所帮助。
标签:函数,小数,随机,随机数,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
excel表格设置变大的方法
2022-09-21 21:07:42
赛博朋克2077怎么玩?赛博朋克2077推倒攻略
2022-09-17 17:28:07
![](https://img.aspxhome.com/file/2023/6/a324799_0s.jpg)
Win10打开steam创意工坊显示错误代码如何解决?
2022-09-09 10:23:16
![](https://img.aspxhome.com/file/2023/25/a218187_0s.jpg)
word2016如何设置目录中的文本格式
2023-11-20 06:20:48
![](https://img.aspxhome.com/file/2023/0/17710_0s.jpg)
如何制作网线?网线制作方法图解
2022-09-02 16:35:46
![](https://img.aspxhome.com/file/2023/6/a325826_0s.jpg)
QQ不显示地理位置的方法
2023-02-23 12:02:42
![](https://img.aspxhome.com/file/2023/9/a340785_0s.jpg)
Mac电脑设置访达边栏图标大小的方法
2023-08-24 12:25:29
![](https://img.aspxhome.com/file/2023/4/a208144_0s.png)
电脑版wps文档如何在页眉中插入图片
2022-01-21 15:09:56
![](https://img.aspxhome.com/file/2023/5/a183205_0s.png)
word文档怎么输入上标和下标方法
2023-11-27 06:06:25
![](https://img.aspxhome.com/file/2023/2/17652_0s.jpg)
AMD双显卡切换型号怎么删除右键的AMD相关选项?
2023-10-15 23:25:45
![](https://img.aspxhome.com/file/2023/6/a322449_0s.jpg)
怎么使用U盘制作Win10系统修复工具?
2023-11-23 22:58:05
![](https://img.aspxhome.com/file/2023/5/50785_0s.png)
Win11截图快捷键是什么 Win11快速截图方法汇总
2022-04-25 04:35:26
![](https://img.aspxhome.com/file/2023/1/a280403_0s.png)
win10系统开始菜单打不开要怎么解决?
2022-11-07 08:08:10
![](https://img.aspxhome.com/file/2023/26/a223832_0s.png)
Win10专业版搜索不到共享打印机怎么办?Win10专业版搜索不到共享打印机解决办法
2022-02-01 03:43:27
![](https://img.aspxhome.com/file/2023/26/a223598_0s.png)
Mac新手需掌握的操作技巧——屏幕篇
2023-12-01 18:26:25
![](https://img.aspxhome.com/file/2023/8/a204438_0s.jpeg)
暴风影音如何慢放视频?暴风影音慢放视频的教程
2022-08-06 09:17:09
![](https://img.aspxhome.com/file/2023/8/a337965_0s.jpg)
Win11中怎么启用团队聊天功能?
2023-05-20 13:27:09
![](https://img.aspxhome.com/file/2023/27/a238094_0s.jpg)
win10 2004更新错误0xc1900404解决方法
2023-12-22 17:55:00
![](https://img.aspxhome.com/file/2023/2/a286675_0s.png)
win7系统局域网抢网速的方法
2022-09-04 13:33:59
![](https://img.aspxhome.com/file/2023/29/a262069_0s.png)
excel中更换两行的方法
2023-06-23 13:20:58