VBA求所选范围最小值,循环结构
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/07/29 14:05:52
VBA求所选范围最小值,循环结构
如题.计算所选工作表区域中单元格的最小值,用MsgBox函数输出结果.
注意:循环结构!
如题.计算所选工作表区域中单元格的最小值,用MsgBox函数输出结果.
注意:循环结构!
![VBA求所选范围最小值,循环结构](/uploads/image/z/18613218-66-8.jpg?t=VBA%E6%B1%82%E6%89%80%E9%80%89%E8%8C%83%E5%9B%B4%E6%9C%80%E5%B0%8F%E5%80%BC%2C%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84)
你老师要的两重循环:Sub test()
Dim i As Long, j As Integer, MyMin As Double
Dim a As Long, b As Integer
a = Selection.Row
b = Selection.Column
MyMin = 9E+99
For i = 1 To Selection.Rows.Count
For j = 1 To Selection.Columns.Count
If Cells(a + i - 1, b + j - 1).Value < MyMin Then
MyMin = Cells(a + i - 1, b + j - 1).Value
End If
Next j
Next i
MsgBox "最小值为" & MyMin
End Su
Dim i As Long, j As Integer, MyMin As Double
Dim a As Long, b As Integer
a = Selection.Row
b = Selection.Column
MyMin = 9E+99
For i = 1 To Selection.Rows.Count
For j = 1 To Selection.Columns.Count
If Cells(a + i - 1, b + j - 1).Value < MyMin Then
MyMin = Cells(a + i - 1, b + j - 1).Value
End If
Next j
Next i
MsgBox "最小值为" & MyMin
End Su