首页 > 解决方案 > 如何在点击 Then 和 End If 语句之前退出 If?

问题描述

我需要一种在“那么”之前结束“如果”的方法

For i = 0 To Main.[B10000].End(xlUp).Row - 4

    POD = Trim(Main.Range("B5").Offset(i, 0))
    If POD <> "" Then

        L2 = "https:/AAAAA" & POD

        P.Open "Get", L2
        P.SetAutoLogonPolicy 0
        P.send
        P.waitForResponse

        D.body.innerHTML = P.responseText

        For Each R In D.getElementsByClassName("col-md-7")
            If InStr(1, R.innerText, "pod is not found on floor") <> 0 Then
                Main.Range("B5").Offset(i, 1) = "Offline"

                **'I need end here if = Offline**

            Else
                Main.Range("B5").Offset(i, 1) = "Online"
            End If
        Next R
    End If
Next i

End Sub

标签: excelvbaif-statement

解决方案


正如 AJD 提到的,您可以在将 B5 单元格的值设置为“离线”后退出

For i = 0 To Main.[B10000].End(xlUp).Row - 4

POD = Trim(Main.Range("B5").Offset(i, 0))
If POD <> "" Then

    L2 = "https:/AAAAA" & POD

    P.Open "Get", L2
    P.SetAutoLogonPolicy 0
    P.send
    P.waitForResponse

    D.body.innerHTML = P.responseText

    For Each R In D.getElementsByClassName("col-md-7")
        If InStr(1, R.innerText, "pod is not found on floor") <> 0 Then
            Main.Range("B5").Offset(i, 1) = "Offline"
            Exit For
        Else
            Main.Range("B5").Offset(i, 1) = "Online"
        End If
    Next R
End If

接下来我


推荐阅读