Excel中如何得到不重复的随机数。

Excel中如何得到不重复的随机数?情况下面操作方法。

材料/工具

Excel

方法

启动Excel

按Alt + F11启动VBA

选择要生成随机数的工作表。

输入以下代码:

Sub m()

R来自ange("A:A").ClearContents'      这里是A列,根据需要修改

For i = 1 To 10'                          这里是10个数字,根据需要修改

kkk:

Randomize

x = Int(Rnd * 10) + 1

If Application.CountIf(Range("A:A"), x) = 0 Then

Cells(i, 1) = x

Else

GoTo kkk

End If

Next i

End Sub

按F5运行,即可得到结果。