View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Papa Jonah Papa Jonah is offline
external usenet poster
 
Posts: 148
Default If - End if problem

Rick,
I have tried that. However, when I use "ElseIf" I still get a compile error
"else without if" and highlights "ElseIf locale = "L" then"

This is what I have currently:
If locale = "P" Then Selection.Interior.ColorIndex = 3
Else: If locale = "L" Then Selection.Interior.ColorIndex = 6
Else: Selection.Interior.ColorIndex = 9
End If

When I run the macro, I am currently getting a "Compile Error - Else without
If" with the first "Else:" highlighted.

I don't see the difference in what I have tried and what has been suggested
- but it still isn't working.
Thanks for bearing with me.

Papa J

"Rick Rothstein (MVP - VB)" wrote:

Did you try what I posted (it does work)?

Rick


"Papa Jonah" wrote in message
...
I totally agree and tried that at first. All crammed together was the only
way I could stop the stupid thing from giving me "Else without If" errors.

"Rick Rothstein (MVP - VB)" wrote:

You will do yourself the biggest favor if you stop trying to cram all of
your If-Then-Else blocks into one line... trust me on that. Also, when
you
have to do future edits to your code, not cramming everything into one
line
will make reading your code much easier. Consider this rearrangement of
your
code...

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

Which do you think will be easier to work with 6 months down the road
when
you have to modify your code for some reason?

You definitely should use the structure above, but I thought you might
like
to see one of several possible "true" one-line code statements that will
do
the same thing as the above code...

Selection.Interior.ColorIndex = 9 + 6 * (locale = "P") + 3 * (locale =
"L")

Rick


"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