任何帮助都是最好的。我似乎不能让ELSEIF与AND一起工作。
我正在使用一个用户表单。当他们按下该按钮时,将出现带有复选框的用户窗体。当两个复选框都选中时,我遇到问题。它们单独工作得很好,
我不确定我做错了什么。任何帮助都将不胜感激
If Intact.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
End With
ElseIf Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storCompugen
End With
ElseIf Intact.Value And Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
storDate1 = Sheets("escalation").Cells(Selection.Row, 2)
storProject1 = Sheets("escalation").Cells(Selection.Row, 3)
StorBill1 = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
.formfields("text5").Result = storDate1
.formfields("Text6").Result = storProject1
.formfields("Text7").Result = StorBill1
.formfields("Text8").Result = storCompugen
End With
End If提前感谢
发布于 2017-03-09 00:51:24
尝试更改顺序。否则,只要满足一个条件,If子句就会退出。
If Intact.Value And Compugen.Value Then
'code
ElseIf Intact.Value Then
'code
ElseIf Compugen.Value Then
'code
End If发布于 2017-03-09 00:49:16
如果Intact.Value = True为真,那么将运行第一个块,而不是第三个块。
类似地,如果Intact.Value = True不为true,而Compugen.Value = True为true,那么第二个块将运行。
因此,您可以看到第三个块是不可访问的。
解决方案是将Intact.Value = True And Compugen.Value = True案例放在组中的第一位。
最后,Foo.Value = True是更简单的Foo.Value的重言式。您可以删除所有显式的= True比较。
https://stackoverflow.com/questions/42677067
复制相似问题