IF / IF Else跳过OR语句

时间:2019-10-10 09:22:25

标签: excel vba

因此,我正在编写and语句,该语句还检查例如值是x还是y。但是,只有在我的or语句中第一个x语句为true而不是y语句为true时,它才会执行代码。

因此,基本上,当单元格17中的值等于“ Recovery Demand Issued”时,它会跳过第二个if语句,但是当单元格17中的值等于“处于恢复中”时,它就很好了

不确定为什么要跳过第二个if语句,我和/或语句的结构是否正确?

If dataSheet.Cells(x, 6) = "Serena Hayward" And dataSheet.Cells(x, 8) = "Open" And dataSheet.Cells(x, 17) = "In Recovery" Or dataSheet.Cells(x, 17) = "Recovery Demand Issued" Then serenaBool = True


If chantalBool = True And cellDateDbl <= julyFinishDbl And cellDateDbl >= julyStartDbl Then
chantalJulyTotalDemanded = dataSheet.Cells(x, 10) + chantalJulyTotalDemanded

ElseIf serenaBool = True And cellDateDbl <= julyFinishDbl And cellDateDbl >= julyStartDbl Then
serenaJulyTotalDemanded = dataSheet.Cells(x, 10) + serenaJulyTotalDemanded

1 个答案:

答案 0 :(得分:0)

由于您的调试非常困难,因此我会亲自将其布置如下,请注意if语句中“或”参数周围的()。

        Sub test()
        Dim serenabool As Boolean
            serenabool = False
        Dim chantelbool As Boolean
            chantelbool = False

        If datasheet.Cells(x, 6) = "Serena Hayward" And datasheet.Cells(x, 8) = "Open" And (datasheet.Cells(x, 17) = "In Recovery" Or datasheet.Cells(x, 17) = "Recovery Demand Issued") Then serenabool = True
        If datasheet.Cells(x, 6) = "Chantel Surname" And datasheet.Cells(x, 8) = "Open" And (datasheet.Cells(x, 17) = "In Recovery" Or datasheet.Cells(x, 17) = "Recovery Demand Issued") Then chantelbool = True

        If chantalBool = True And cellDateDbl <= julyFinishDbl And cellDateDbl >= julyStartDbl Then
        chantalJulyTotalDemanded = datasheet.Cells(x, 10) + chantalJulyTotalDemanded
        End If

        If serenabool = True And cellDateDbl <= julyFinishDbl And cellDateDbl >= julyStartDbl Then
        serenaJulyTotalDemanded = datasheet.Cells(x, 10) + serenaJulyTotalDemanded
        End If

        Debug.Print "Serena is " & serenabool
        Debug.Print "Chantel is " & chantelbool

        End Sub