excel随机数生成问题 要求相邻两数之差不得大于0.02

2025-12-25 08:30:14
推荐回答(1个)
回答1:

sheet1,第一行第一格开始连写40个
Sub r40()

While i <= 40

i = i + 1
Randomize

Sheet1.Cells(1, i).Value = 2.37 + Round(Rnd() * 0.09, 2)

If i <> 1 Then
If Abs(Sheet1.Cells(1, i).Value - Sheet1.Cells(1, i).Value) > 0.02 Then
i = i - 1
End If
End If
Wend
End Sub