View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default If - End if problem

Just as a follow up to this sub-thread... I never splice multiple commands
together using the colon operator to join them. Your attempted use of them
in the If-ElseIf-Else-Then statements I posted is what caused my original
code to fail you... you didn't splice them together correctly. Having been
programming for some 25+ years, my advice would be for you to abandon trying
to cram your If-ElseIf-Else-Then blocks together the way you showed and
simply space them out (as I did in my first posting)... you will find them
far more readable six months down the road when, for whatever reason, you
have to modify your code. More importantly, if you (ever) work in a team
shop, your co-workers who may be called on to modify your code will thank
you for doing so also.

Rick


"Papa Jonah" wrote in message
...
Apparently, after cutting and pasting yours, the only difference I see is
the
indentation of yours between If and End if - but yours works.
Thanks

"Ron Rosenfeld" wrote:

On Mon, 17 Dec 2007 14:44:34 -0800, Papa Jonah
wrote:

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



This:

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

or this:

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


Both work OK here.
--ron