一个MsgBox显示所有通过和失败 [英] One MsgBox To show all passes and fails
问题描述
我正试图在一个消息框中添加样本的合格和不合格.
I am trying to make one message box to include passes and fails of samples.
所有高于0.24的范围都是不合格的,下面是合格的,要在一个框中显示合格和不合格的情况,并给出相应的样本#
All Ranges above 0.24 are a fail and below are a pass, and that to show in one box the passes and fails with correspondent sample #
下面的代码一个接一个地显示框,甚至错误地显示它们,有些是空白的,有些是不正确的.
The code below, show the boxes one by one and even incorrectly, some are blank and some not correct.
请你帮我这个忙.谢谢
Sub MsgB()
Dim x As Long
For x = 2 To 8
If Sheet2.Range("B" & x).Value < 0.24 Then
y = Sheet2.Range("A" & x).Value
MsgBox "Pass: " & y
Else
MsgBox "Fail: " & y
End If
Next
End Sub
推荐答案
您可以将结果累积在两个字符串变量中,如下所示,并在循环完成后显示结果.另外,仅当 y
的值小于 0.24
时才设置.您需要在 If
之前设置 y
.
You could accumulate the results in two string variables as shown below, and display the results after the loop has completed. Also, y
is set only if the value is smaller than 0.24
. You need to set y
before the If
.
Sub MsgB()
Dim x As Long
Dim pass as String
pass = ""
Dim fail as String
fail = ""
For x = 2 To 8
y = Sheet2.Range("A" & x).Value
If Sheet2.Range("B" & x).Value < 0.24 Then
pass = pass & ", " & y
Else
fail = fail & ", " & y
End If
Next
' Print pass and fail, removing the leading ", ".
pass = Right(pass, Len(pass) - 2)
fail = Right(fail, Len(fail) - 2)
MsgBox "Pass: " & pass & vbCrLf & "Fail: " & fail
结束子
这篇关于一个MsgBox显示所有通过和失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!