选择带字符串的Case

时间:2014-08-05 14:50:57

标签: excel vba excel-vba

我对使用Select Case和字符串进行比较感到沮丧。

我只需要检查某人是否发表评论,或者只是通过扫描不同的对象来继续。

所以我在声明中读到并检查是否有部件号进入(总是以N开头)或者如果没有,我知道接下来要去哪里。

由于接下来可能发生三种情况,我无法接受if temp = Left(temp, 1) = "N"

我的错误在哪里?

            temp = Application.InputBox(Prompt:="Would you like to make a comment?" & vbCrLf & "If not please continue with next scan. ", Title:="Comment or go on", Type:=2)
            Select Case temp

                Case Is = Left(temp, 1) = "N"
                'New scan - next number got scanned
                    MsgBox ("Controlmessage - N Case")
                    i = i + 1
                    .Cells(i, "D").Select
                    temp = ""

            End Select

1 个答案:

答案 0 :(得分:6)

试试这个

Sub Main()

    temp = Application.InputBox(Prompt:="Would you like to make a comment?" & vbCrLf & "If not please continue with next scan. ", Title:="Comment or go on", Type:=2)

    Select Case UCase(Left(temp, 1))
        Case "N"
            MsgBox "N"
        Case "C"
            MsgBox "C"
        Case Else
            MsgBox "something else"
    End Select

End Sub