【问题标题】:Excel Macro YesNo message box, different directions for Yes and NoExcel 宏 YesNo 消息框,Yes 和 No 的不同方向
【发布时间】:2016-06-15 02:33:54
【问题描述】:

用户在 YesNo 消息框中有两个选项。如果否,它会执行一定的过滤器序列,但如果用户对消息框问题回答是,我想过滤另一列。目前,在“Else”处,我收到一条错误消息,内容为“编译错误:赋值左侧的函数调用必须返回 Variant 或 Object” ,但仅在用户选择否时过滤。

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

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    这里发生了一些事情。 : 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,除非你确定这是你想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 1970-01-01
      相关资源
      最近更新 更多