简体   繁体   English

将IF语句分配给Form控件组合框

[英]Assign IF statement to Form control combobox

I have a form control combobox (named DropDown1) on a worksheet. 我在工作表上有一个窗体控件组合框(名为DropDown1)。 I'm trying to assign an if statement but have been unable to do so. 我正在尝试分配一个if语句,但是无法这样做。

Sub DropDown1_Change()

    If DropDown1.Value = "test" Then
        Print (1)
    Else
        Print (2)
    End If

End Sub

There is nothing wrong with the IF statement itself. IF语句本身没有错。 What is wrong is what you are doing after the branching occurs. 出问题的是分支发生之后您正在做什么。

In other words, the is no Print command. 换句话说,是no Print命令。 You can use Debug.Print, or you can use MsgBox. 您可以使用Debug.Print,也可以使用MsgBox。

Here is how the code should read: 代码如下所示:

Private Sub DropDown1_Change()
    If DropDown1.Value = "test" Then
        Debug.Print 1
    Else
        Debug.Print 2
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM