选择带字符串的Case

Joh*_*aen 3 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
Run Code Online (Sandbox Code Playgroud)

小智 7

试试这个

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
Run Code Online (Sandbox Code Playgroud)