How to show all fails if there is any, if not then show no fail box

女生的网名这么多〃 提交于 2019-12-02 05:57:02

You need to feed the failsvariable with the ranges you want to show and then check if your variable is empty or not. Also, there is no need to feed a passesvariable because it will always be the same:

Option Explicit
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
                If fails = vbNullString Then
                    fails = .Range("A" & x)
                Else
                    fails = fails & ", " & .Range("A" & x)
                End If
            End If
        Next x
    End With

    'Here you check wether you send one message or the other
    If Not fails = vbNullString Then
        MsgBox "Failed Strut: " & fails
    Else
        MsgBox "There are no fails"
    End If

    'Other attempts
    'MsgBox passes
    'fails = Right(fails, Len(fails) - 2)
    'MsgBox "Failed Strut: " & fails

End Sub

Finally, indenting correctly your code makes it more easy to read.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!