VBA在msg框中打印一个值

时间:2016-10-10 14:39:16

标签: excel vba excel-vba

我被困在学校的任务中,这就是我必须要做的事情:

这是我目前的代码:

2 个答案:

答案 0 :(得分:3)

您需要循环加载的数组:

Sub Ratio()

Dim OperatingRatio() As Double
Dim j As Long

With Sheets("Summary")
    OperatingRatio = .Cells("I80:M80").Value

    For j = LBound(OperatingRatio, 2) To UBound(OperatingRatio, 2)
        If OperatingRatio(1, j) > 100 Then
            MsgBox .Cells(14, 9 + j)
            .Cells(80, 9 + j).Interior.Color = vbRed
        Else
        End If
    Next j
End With

End Sub

答案 1 :(得分:0)

最好是单独遍历所有单元格,如下所示:

Dim i As Integer

'9 means column I and 13 is column M
For i = 9 To 13
    ' Getting the percent values
    Debug.Print Worksheets("Summary").Cells(80, i).Value
Next

这样你就可以自己继续。