View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Conan Kelly Conan Kelly is offline
external usenet poster
 
Posts: 419
Default If - End if problem

Papa Jonah,

What version of XL are you using? I'm using XL 2003 and I can't get the VBE
to correct "ElseIf" to "Else: If". I get a "Compile Error: Expected: End of
statement".

Also, the Help document on If...Then...Else doesn't explicitly say that
ElseIf can not be used in the 1-line syntax, BUT HOW IT IS WRITTEN suggests
that you need to use the Block syntax if you want ElseIf's.

HTH,

Conan




"Papa Jonah" wrote in message
...
I tried that but the program "corrects" it automatically to make it Else:
if.
I was also getting a similar error of elses without ifs until I put it all
on one line.



"Conan Kelly" wrote:

Papa Jonah,

Use "ElseIf" instead of "Else: If" and "Else" instead of "Else:"

Also, it looks like you are trying to do If...Then...ElseIf...Then...Else
all on one line. If I remember correctly, this is possible and you don't
need the "End If" to terminate it (don't know if it will ignore it if it
is
there....haven't tried that).


To do it on multiple lines, use this ("End If" is required):

If locale = "P" Then
Selection.Interior.ColorIndex = 3
ElseIf locale = "L" Then
Selection.Interior.ColorIndex = 6
Else
Selection.Interior.ColorIndex = 9
End If


HTH,

Conan




"Papa Jonah" wrote in message
...
What is wrong with this?
If locale = "P" Then Selection.Interior.ColorIndex = 3 Else: If locale
=
"L"
Then _
Selection.Interior.ColorIndex = 6 Else: Selection.Interior.ColorIndex =
9
End If

I keep getting an End If without If block error. I don't understand
the
help.
I have an If statement and and End If statement.

Papa J