首页 > 中学考试杂题 > 题目详情
如何在Excel中的某一列用vba产生五组1到10的随机数?如何在Excel中的某一列产生五组1到10的随机数?例如:在
题目内容:
如何在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中的某一列用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
本题链接: