2016-06-14 44 views
0

用户在是否消息框中有两个选项。如果否,它执行一定的过滤器序列,但如果用户对消息框问题回答“是”,我想过滤另一列。目前,在“Else”中,我收到一条错误消息:“编译错误:赋值左侧的函数调用必须返回Variant或Object”如果我取出“Else”,并且之后的代码,宏运行平稳,但仅当用户选择时才过滤。编号为Excel宏是否没有消息框,对于是和否的不同方向

If MsgBox("Is This Item Catch Weight?", vbYesNo) = vbNo Then 
    retval = InputBox("Please Enter PO Cost") 
    ActiveSheet.Range("$A$1:$CL$293662").AutoFilter Field:=71,   Criteria1:="=" & retval 
    retval = InputBox("Please Enter Net Weight") 
    ActiveSheet.Range("$A$1:$CL$293662").AutoFilter Field:=41, Criteria1:="=" & retval 
Else: MsgBox("Is This Item Catch Weight?", vbYesNo) = vbYes 
    retval = InputBox("Please Enter PO Cost") 
    ActiveSheet.Range("$A$1:$CL$293662").AutoFilter Field:=71, Criteria1:="=" & retval 
End If 
End If 

回答

2

这里发生了一些事情。在VBA代码:换行字符等等之类

Else: MsgBox("Is This Item Catch Weight?", vbYesNo) = vbYes 

线其实是一样的

Else 
    MsgBox("Is This Item Catch Weight?", vbYesNo) = vbYes 

这是不是你想要的。

最后还有一个额外的End If。删除。

调用消息框多次出现可能不是oyu想要的。可能你想显示消息框,得到结果然后用它做点什么。

Dim response As VbMsgBoxResult 
response = MsgBox("Is This Item Catch Weight?", vbYesNo) 
If response = vbNo Then 
    'do stuff for yes 
ElseIf response = vbYes Then 
    ' do stuff for No 
End If 

我也建议不要使用ActiveSheet,除非你确信这就是你想要的。

+0

美丽,谢谢布拉德! – cam

相关问题