【发布时间】:2019-06-10 15:12:12
【问题描述】:
我想用对应的样本显示失败的 MsgBox。如果不显示另一个没有失败的 MsgBox。
我觉得我快到了,但有些事情搞砸了。
如果我将 MsgBox 放入循环中,则 MsgBox 会出现不止一次,如果我把它放出来,它会同时显示 MsgBox 的“失败”(如果有)和“没有失败”
我怎样才能用(If 语句)只显示其中一个,当然也显示一次。显示全部失败的框或显示没有的框。
我运行的代码:
Sub Box()
Dim x As Long
Dim fails As String
'Dim passes As String
With Sheet2
For x = 2 To 8
If .Range("E" & x).Value > 0.24 Then
fails = fails & ", " & .Range("A" & x)
MsgBox "Failed Strut: " & fails
ElseIf .Range("E" & x).Value < 0.24 Then
passes = "There are no fails"
MsgBox passes
End If
Next x
End With
'Other attempts
'MsgBox passes
'fails = Right(fails, Len(fails) - 2)
'MsgBox "Failed Strut: " & fails
End Sub
【问题讨论】: