作业帮 > 综合 > 作业

VBA求所选范围最小值,循环结构

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/14 09:52:43
VBA求所选范围最小值,循环结构
如题.计算所选工作表区域中单元格的最小值,用MsgBox函数输出结果.
注意:循环结构!
你老师要的两重循环: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