0

想问一下,我可以在一个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
4

2 回答 2

0

这是你正在尝试的吗?

就像我在评论中说的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
于 2013-02-20T08:18:24.950 回答
0

您还可以用逗号指定多个条件分隔。

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
于 2013-02-20T08:25:39.370 回答