嵌套的if语句在excel-vba中使用yes no message box

时间:2017-10-20 10:16:11

标签: excel vba excel-vba if-statement nested

大家好,我一直在这里游荡一段时间,并在excel中节省了一些不错的时间,但这是我的第一篇文章。

我试图将问题和答案的流程图转换为excel中的程序,该程序将询问我们的客户如何使用车辆帮助他们在订购时选择正确的选项。 如果他们对第一个问题的回答是肯定的,那么我已经注释了代码将采用的路由,并且对于否,我已经注释了代码的两个部分。但是,如果代码的两个部分都没有注释,我就无法对第一个问题的无答案做出回应。我确定这是一个简单的答案,我只是看不到,我已经在它上面几个小时,并在谷歌爬行,但我只是不能让它工作,我一直在玩别的如果和其他,看看是否有所作为,结束如果,结束子...我迷路了  任何人都可以告诉我哪里出错了吗?

(要运行此代码,用户必须单击制造商徽标的图像,打开显示不同车辆图像的用户窗体,单击图像将运行下面的代码)

Private Sub Image6_Click()
Dim Answer1 As Integer
Dim Answer2 As Integer
Dim Answer3 As Integer
Dim Answer4 As Integer
Dim Answer5 As Integer


Answer1 = MsgBox("Is the vehicles load more than 5mA at engine off (overnight with no means of isolation) e.g. Tracker or CCTV?", vbYesNo + vbQuestion, "BEMM Tool")
If Answer1 = vbYes Then
Answer2 = MsgBox("Will large electrical loads be drawn from the system (40A-250A)e.g. Tipper, tail lifts, welfare van, inverters greater than 480W, microwaves, powertools?", vbYesNo + vbQuestion, "BEMM Tool")
        If Answer2 = vbYes Then
        MsgBox "Your vehicle will require the twin AGM battery upgrade, and the upgraded 210A alternator ordering from the factory (number:HFL & A736)"
        Exit Sub


        Else
        If Answer2 = vbNo Then
        Answer5 = MsgBox("will the system draw loads greater than 30A at engine run e.g. command vehicle, maintenence vehicle, inverter <360W-480W, water boiler, small power tools", vbYesNo + vbQuestion, "BEMM Tool")
            If Answer5 = vbYes Then
            MsgBox "your vehicle will need to be ordered with the twin AGM battery upgrade and standard 150A alternator (order number: a736)"
            Exit Sub

            Else
            If Answer5 = vbNo Then
            MsgBox "your vehicle will need to be ordered from ford with the twin AGM battery upgrade and standard 150A alternator (order number: a736)"
            Exit Sub


 Else
 If Answer1 = vbNo Then




        Answer3 = MsgBox("will you frequently draw loads less than 30A at engine run,eg. service engineers van, worklamps,ambers,handwash?", vbYesNo + vbQuestion, "BEMM Tool")
        If Answer3 = vbYes Then
        MsgBox "your veichle will need to be ordered with twin flooded batteries and the standard 150A alternator(order number:NXL)"
        Exit Sub

        Else
        If Answer3 = vbNo Then
        Answer4 = MsgBox(" will your vehicle ocasionaly be drawing loads of less than 30A at engine run,e.g. courier van, charging gps/phone, interior lights, small 12v kettle?", vbYesNo + vbQuestion, "BEMM Tool")
            If Answer4 = vbYes Then
            MsgBox "your vehicle will require standard single flooded battery and standard 150a alternator and will not requre factory fit upgrades"
            Exit Sub

            Else
            If Answer4 = vbNo Then
            MsgBox "your vehicle will require standard single flooded battery and standard 150a alternator and will not requre factory fit upgrades"
            Exit Sub




End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

0 个答案:

没有答案