Excel利用VBA生成一列不重复的随机整数
时间:2023-02-25 10:10:19
如果我们要用VBA生成一列不重复的随机整数,可以用下面的VBA代码。本例可以在A1:A100中产生1-100的不重复随机整数。
Sub RndNumberNoRepeat()
Dim TempArr1(99) As Integer, TempArr2(0 To 99, 1 To 1) As Integer
Dim RndNumber As Integer, i As Integer
Randomize (Timer) '初始化随机数生成器
For i = 0 To 99 '产生包含1-100的不重复的随机数列
TempArr1(i) = i
Next i
For i = 99 To 0 Step -1
RndNumber = Int(i * Rnd)
TempArr2(99 - i, 1) = TempArr1(RndNumber) + 1
TempArr1(RndNumber) = TempArr1(i)
Next i
'在A1:A100中输入这些数字
Range("a1:a100").Value = TempArr2
End Sub
标签:Excel,利用,VBA,生成,一列,不,重复,的,随机,整数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
新电脑win11跳过创建账户的方法
2023-03-13 18:53:31
![](https://img.aspxhome.com/file/2023/1/a274629_0s.jpg)
电脑文件被锁无法删除怎么办?
2022-12-13 10:36:31
![](https://img.aspxhome.com/file/2023/4/a307568_0s.png)
怎样为word文字分栏
2023-04-02 00:45:12
火绒“浏览器保护”怎么用?浏览器保护功能使用技巧分享
2023-09-23 20:30:20
![](https://img.aspxhome.com/file/2023/7/a331749_0s.jpg)
Word如何删除页眉横线?Word删除页眉横线的6种方法
2023-07-15 07:46:50
![](https://img.aspxhome.com/file/2023/7/31217_0s.gif)
Win11系统线程异常未处理怎么办?Win11系统线程异常未处理解决方法
2023-12-02 08:00:42
![](https://img.aspxhome.com/file/2023/27/a235799_0s.png)
PPT简单制作一份简历
2023-08-20 17:51:41
![](https://img.aspxhome.com/file/2023/10/a346872_0s.jpg)
wps表格如何设置单元格
2022-04-25 10:43:38
win101909版本KB4540673更新了什么_win101909版本KB4540673更新内容曝光
2022-08-14 18:59:05
![](https://img.aspxhome.com/file/2023/5/a317124_0s.jpg)
win7系统下如何关闭空闲的服务进程?
2023-11-21 02:25:02
![](https://img.aspxhome.com/file/2023/4/a312120_0s.jpg)
PPT柱状图网格线怎么添加或删除?PPT添加或删除柱状图网格线的方法
2023-03-03 12:39:45
![](https://img.aspxhome.com/file/2023/10/a350278_0s.jpg)
找回被删除的vista的自带驱动
2022-11-09 11:42:02
win11录屏怎么录声音?win11录屏录制声音的方法
2022-06-27 09:06:53
![](https://img.aspxhome.com/file/2023/30/a269967_0s.jpg)
Excel如何彩色表格显示打印两不误
2022-10-29 02:29:25
![](https://img.aspxhome.com/file/2023/5/37135_0s.png)
win10系统开启摄像头就绿屏/蓝屏的有效解决方法
2023-03-18 13:49:57
![](https://img.aspxhome.com/file/2023/4/a310241_0s.jpg)
win10网络被禁用怎么办_win10网络被禁用解决方法
2022-08-24 07:46:11
![](https://img.aspxhome.com/file/2023/2/a288805_0s.jpg)
iCloud 空间被 Mac 桌面和文稿占用的解决方法
2023-12-06 13:10:13
![](https://img.aspxhome.com/file/2023/1/a210781_0s.png)
Win10玩红色警戒调全屏的操作方法
2022-05-13 23:34:41
![](https://img.aspxhome.com/file/2023/1/a280006_0s.png)
在Windows XP中使用传真
2023-06-24 07:40:48
word文档的圆圈内如何更改数字?word编辑圆圈中数字的方法
2022-09-14 16:01:20
![](https://img.aspxhome.com/file/2023/1/a273236_0s.png)