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

后端 未结 1 703
鱼传尺愫
鱼传尺愫 2021-01-24 03:43

I want to show MsgBox of fails with correspondent samples. If non show another MsgBox with no fail.

I feel I am almost there but have something messing.

If I put

相关标签:
1条回答
  • 2021-01-24 03:53

    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.

    0 讨论(0)
提交回复
热议问题