4 Leave Cover
4 Leave Cover

Reputation: 1276

EXCEL VBA Select Case error checking

I would like to do an error checking like in the code section below. However, I do not know how to do it properly. Please provide some guidance. Thanks in advance.

Select Case Trim(y)
    Case Is = ""
        MsgBox ("Empty field!")

    Case (UCase(Left(y, 1)) = "=") '<--This line requires guidance
        MsgBox ("invalid input")
End Select

Upvotes: 0

Views: 2430

Answers (1)

collapsar
collapsar

Reputation: 17258

this won't compile. rather try

Select Case UCase(Left(Trim(y), 1))
    Case ""
        MsgBox ("Empty field!")

    Case "="
        MsgBox ("invalid input")
End Select

there are alternatives on how to structure your select or whether to use it at all (you could opt for cascading if statements, for example):

Select Case Left(y,1)
    Case "="
        MsgBox ("invalid input")

    Case Else
        If Trim(y) = "" Then
           MsgBox ("Empty field!")
        End If
End Select

Upvotes: 3

Related Questions