[英]can insert multiple instruction under one case excel-vba?
要问,我可以在一个case语句下使用多条指令吗?不想使用if..then,因为我有7个以上的条件。 我想做的是,如果组合框的值为“ this”,然后将新行插入正确的行,然后将组合框的值添加到新创建的行中。 这是示例:
Case ComboBox1.Value = "Venofix"
instruction 1 ~> count the number of row of "venofix"
instruction 2 ~> insert new row at the last row
instruction 3 ~> insert data from combobox
Case ComboBox1.Value = "Penofix"
instruction 1 ~> count the number of row of "penofix"
instruction 2 ~> insert new row at the last row
instruction 3 ~> insert data from combobox
这是您要尝试的吗?
就像我在评论中I would however keep Instruction 2 and 3 out of the select case (not because it won't work inside the select case but simply because I would want to avoid duplicate code)
Sub Sample()
Select Case ComboBox1.Value
Case "Venofix"
'instruction 1 ~> count the number of row of "venofix"
Case "Penofix"
'instruction 1 ~> count the number of row of "penofix"
End Select
'instruction 2 ~> insert new row at the last row
'instruction 3 ~> insert data from combobox
End Sub
您还可以指定多个条件,以逗号分隔。
Sub Sample()
Dim conDition As String
conDition = ComboBox1.Value
Select Case conDition
Case "Venofix"
Debug.Print "instruction 1"
Case "Penofix"
Debug.Print "instruction 1"
Case "test1", "test2"
Debug.Print "more than 1 instruction"
End Select
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.