EXCEL中,如何从1——49 这49个数值中随机选出36个不重复的的随机数? 最好50000组宏程序,谢

EXCEL中,如何从1——49 这49个数值中随机选出36个不重复的的随机数? 最好50000组宏程序,谢,第1张

代码如下:这个代码运行一次可以生成50组,如果你要生成50000组,多点几次,你也可以修改第一个for循环For j = 1 To 50,改成For j = 1 To 50000,这样可以一次跑出50000组,但是你的电脑要足够好,否则会跑死你的Excel.

Sub 随机数()

Dim str As String

Dim i, j, x As Integer

Range("A1").EntireColumn.ClearContents

str = 49

For j = 1 To 50

x = Int((50 - 1) * Rnd() + 1)

For i = 1 To 36

Do While WorksheetFunction.CountIf(Range(Cells(1, 1), Cells(1, i)), x) >0

x = Int((50 - 1) * Rnd() + 1)

Loop

Cells(1, i) = x

Next

Rows(1).Insert shift:=xlUp

Next

End Sub

Sub SuiJi()

Dim S(1 To 30, 1 To 49) As Integer

For i = 1 To 30

For j = 1 To 49

S(i, j) = j

Next

Next

For i = 1 To 30

For j = 1 To 49

w = Int(Rnd() * 49) + 1

tmp = S(i, w)

S(i, w) = S(i, j)

S(i, j) = tmp

Next

For r = 1 To 7

ShuChu = ""

For c = 1 To 7

ShuChu = S(i, (r - 1) * 7 + c) &"," &ShuChu

Next

ShuChu = Left(ShuChu, Len(ShuChu) - 1)

Cells((i - 1) * 7 + r, 2) = ShuChu

Next

Range("A" &(i - 1) * 7 + 1 &":A" &(i - 1) * 7 + 7).Merge

Range("A" &(i - 1) * 7 + 1) = i

Next

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12471848.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存