excel vba 求50个随机数字的最大值和最小值?(不要公式,我是学习下)
展开全部
Sub test()
Dim mydate(1 To 50) As Single
Dim i As Integer, Maxdate As Single, Mindate As Single
'因为默认的随机数据范围在 0~1之间
Maxdate = -1
Mindate = 9999
Randomize
For i = 1 To 50
mydate(i) = Rnd * 9 + 1 '产生1~10的随机数
If mydate(i) > Maxdate Then Maxdate = mydate(i)
If mydate(i) < Mindate Then Mindate = mydate(i)
Next i
MsgBox "最大数与最小数分别为:" & Maxdate & "、" & Mindate & Chr(13) & Chr(13) _
& "50个随机数保存在数组 mydate(50) 中", vbInformation
End Sub
希望能对楼主有帮助。Good luck!
Dim mydate(1 To 50) As Single
Dim i As Integer, Maxdate As Single, Mindate As Single
'因为默认的随机数据范围在 0~1之间
Maxdate = -1
Mindate = 9999
Randomize
For i = 1 To 50
mydate(i) = Rnd * 9 + 1 '产生1~10的随机数
If mydate(i) > Maxdate Then Maxdate = mydate(i)
If mydate(i) < Mindate Then Mindate = mydate(i)
Next i
MsgBox "最大数与最小数分别为:" & Maxdate & "、" & Mindate & Chr(13) & Chr(13) _
& "50个随机数保存在数组 mydate(50) 中", vbInformation
End Sub
希望能对楼主有帮助。Good luck!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询