Isu
Isu

Reputation: 127

If not is nothing in multiple conditions

Could some one help me to find the mistake here?

If Not r Is Nothing Then
    r.Select
Else
If Not rr Is Nothing Then
    rr.Select
Else
If Not rrr Is Nothing Then
    rrr.Select
Else
End If

Upvotes: 0

Views: 1677

Answers (1)

OpiesDad
OpiesDad

Reputation: 3435

The problem with your code is that you have used If Else If instead of If ElseIf You need to either do:

If Not r Is Nothing Then
    r.Select
Else
    If Not rr Is Nothing Then
        rr.Select
    Else
       If Not rrr Is Nothing Then
           rrr.Select
       Else
       End If
    End If
 End If

Or

If Not r Is Nothing Then
    r.Select
ElseIf Not rr Is Nothing Then
    rr.Select
ElseIf Not rrr Is Nothing Then
    rrr.Select
Else
End If

The second one is probably better.

Upvotes: 5

Related Questions