Compile Error: Else without If...

I keep getting that message everytime I try to use Else. Obviously I'm doing something wrong but I can't figure out why. I need some help.

K. Here's what I did.

[code]If (Line1 = "A" And Line2 = "B" And Line3 = "C") then msgbox "Blah."
Else
Msgbox "Hmm."
End If[/Code]

It says that whether I leave Else by itself. Can someone please help me?

Thanks.

Comments

  • : I keep getting that message everytime I try to use Else. Obviously I'm doing something wrong but I can't figure out why. I need some help.
    :
    : K. Here's what I did.
    :
    : [code]If (Line1 = "A" And Line2 = "B" And Line3 = "C") then msgbox "Blah."
    : Else
    : Msgbox "Hmm."
    : End If[/Code]
    :
    : It says that whether I leave Else by itself. Can someone please help me?
    :
    : Thanks.
    :

    That is basically because you have something after "Then" in the first line. That indicates single-line syntax for the If...Then statement. Therefor, the next line is an Else without an If.
    [code]
    If ... Then ...
    [/code]
    -or-
    [code]
    If ... Then
    ...
    ElseIf ... Then
    ...
    Else
    ...
    End If
    [/code]
  • So in your example you could try....

    [code]
    If Line1 = "A" and Line2 = "B"
    Msgbox "Blah."
    Else
    Msgbox "Hmm."
    End If
    [/code]


    [black] Regards [/black]

    [Size=4][purple]GazzaLad[/size][/purple]
    [Size=1] [Grey]"Just when you thought your software was idiot proof, along comes a better idiot" :-D[/grey] [/Size]
    [hr]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories