如何在Excel中的某一列用vba产生五组1到10的随机数?
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/11 12:53:33
如何在Excel中的某一列用vba产生五组1到10的随机数?
如何在Excel中的某一列产生五组1到10的随机数?
例如:在A1至A50中产生五组1到10的随机数,产生一组容易实现,可是产生五组就有问题了,每一组产生的随机数要不一样,比如第一组产生的是2,8,10,3,7,5,4,1,9,6.第二组7,10,9,5,6,8,3,1,2,4等!
Public Sub sjs()
Dim rng As Range,rng1 As Range
Dim x As Integer,y As Integer,i As Integer
x = 1
y = 10
m = 50 / 10
For i = 1 To m
Set rng = Range("A(x):A(y)")
rng.ClearContents
Randomize
For Each rng1 In rng
Do
rng1 = Int(Rnd * 10 + 1)
Loop Until Application.WorksheetFunction.CountIf(rng,rng1) = 1
Next
x = x + 10
y = y + 10
Next
End Sub
如何在Excel中的某一列产生五组1到10的随机数?
例如:在A1至A50中产生五组1到10的随机数,产生一组容易实现,可是产生五组就有问题了,每一组产生的随机数要不一样,比如第一组产生的是2,8,10,3,7,5,4,1,9,6.第二组7,10,9,5,6,8,3,1,2,4等!
Public Sub sjs()
Dim rng As Range,rng1 As Range
Dim x As Integer,y As Integer,i As Integer
x = 1
y = 10
m = 50 / 10
For i = 1 To m
Set rng = Range("A(x):A(y)")
rng.ClearContents
Randomize
For Each rng1 In rng
Do
rng1 = Int(Rnd * 10 + 1)
Loop Until Application.WorksheetFunction.CountIf(rng,rng1) = 1
Next
x = x + 10
y = y + 10
Next
End Sub
能够产生一组随机数会了.五组如果不会用循环,就单独用5次就行了.如下:
Public Sub sjs()
'以下第一组
Dim a As Range, a1 As Range
Set a = Range("a1:a10")
a.ClearContents
Randomize
For Each a1 In a
Do
a1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(a, a1) = 1
Next
'以下第二组
Dim b As Range, b1 As Range
Set b = Range("a11:a20")
b.ClearContents
Randomize
For Each b1 In b
Do
b1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(b, b1) = 1
Next
'以下第三组
Dim c As Range, c1 As Range
Set c = Range("a21:a30")
c.ClearContents
Randomize
For Each c1 In c
Do
c1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(c, c1) = 1
Next
'以下第四组
Dim d As Range, d1 As Range
Set d = Range("a31:a40")
d.ClearContents
Randomize
For Each d1 In d
Do
d1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(d, d1) = 1
Next
'以下第五组
Dim e As Range, e1 As Range
Set e = Range("a41:a50")
e.ClearContents
Randomize
For Each e1 In e
Do
e1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(e, e1) = 1
Next
End sub
说明:这是个土方法,但可用啊.
Public Sub sjs()
'以下第一组
Dim a As Range, a1 As Range
Set a = Range("a1:a10")
a.ClearContents
Randomize
For Each a1 In a
Do
a1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(a, a1) = 1
Next
'以下第二组
Dim b As Range, b1 As Range
Set b = Range("a11:a20")
b.ClearContents
Randomize
For Each b1 In b
Do
b1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(b, b1) = 1
Next
'以下第三组
Dim c As Range, c1 As Range
Set c = Range("a21:a30")
c.ClearContents
Randomize
For Each c1 In c
Do
c1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(c, c1) = 1
Next
'以下第四组
Dim d As Range, d1 As Range
Set d = Range("a31:a40")
d.ClearContents
Randomize
For Each d1 In d
Do
d1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(d, d1) = 1
Next
'以下第五组
Dim e As Range, e1 As Range
Set e = Range("a41:a50")
e.ClearContents
Randomize
For Each e1 In e
Do
e1 = Int(1 + Rnd * 10)
Loop Until Application.WorksheetFunction.CountIf(e, e1) = 1
Next
End sub
说明:这是个土方法,但可用啊.
如何在Excel中的某一列用vba产生五组1到10的随机数?
如何制作一个EXCEL随机数的表格,我要求在(-10)到20之间产生随机数
Excel 用 VBA 随机数如何保留一位小数
用Excel如何产生0或1的随机数?
如何利用excel中vba自定义函数产生一组指定区间波动的随机数,有合格率限制
用VBA产生1到6之间的随机数用Int((Rnd() * 6) + 1)随机性太差,有没有更好的办法尽量接近真实随机数
如何在excel中对产生的随机数精确到后两位
excel如何在指定的数据中产生随机数
Excel 如何产生固定的随机数
excel随机数是如何产生的?
EXCEL如何在0~100之间产生10的倍数的随机数?
EXCEL 如何在一行中产生1-20范围内不重复的随机数?谢谢!