View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Jeff Meeko Jeff Meeko is offline
external usenet poster
 
Posts: 4
Default compile error: else without if

You have not terminated the If/Then block with the required End If
statement.
Change the last line from End to End If.

jm

"papa" wrote in message
...
My debugger has gotton through the first If/then/else.
However, the second one, which looks to me to be just like
the first is getting hung up.
I have pasted it below, I have used all of your feedback
but this is still stalling.
Please help.

If optCritial.Value = True Then

iconchoice = vbCritical
ElseIf OptQuestion.Value = True Then
iconchoice = vbQuestion
ElseIf OptExclamation.Value = True Then
iconchoice = vbExclamation
ElseIf OptInformation.Value = True Then
iconchoice = vbInformation
ElseIf OptNoIcon.Value = True Then
iconchoice = 0
Else: MsgBox "Abnormal Icon choice.Terminating."
End



-----Original Message-----
If OptOKOnly.Value = True Then ButtonChoice = vbOKOnly
ElseIf OptOKCancel.Value = True Then ButtonChoice =
vbOKCancel

The first line is a single line if statement, so your

second line is
illegal.
If OptOKOnly.Value = True Then
ButtonChoice = vbOKOnly
ElseIf OptOKCancel.Value = True Then
ButtonChoice = vbOKCancel
Elseif . . . Then
' code
Elseif . . . Then
' code
Else

End if

--
Regards,
Tom Ogilvy



"papa" wrote in message
...
That did not change anything. I don't think it is

getting
past the first elseif to even worry about the end.
The following is highlighted in blue:
ElseIf OptOKCancel.Value = True Then

and the following is highlighted in yellow with the

arrow
to the left:
Private Sub CndDisplayMsgbox_Click()


-----Original Message-----
Hi
delete the 'End' statement just before the 'End if'
statement as this
will stop the macro execution

--
Regards
Frank Kabel
Frankfurt, Germany


papa wrote:
I have bee trying to work an example vb problem and

keep
getting a compile error: else without if. I do not
understand why. Here is the code.

Private Sub CndDisplayMsgbox_Click()
Dim ButtonChoice As Integer
Dim iconchoice As Integer
Dim answer As Integer

If OptOKOnly.Value = True Then ButtonChoice =

vbOKOnly
ElseIf OptOKCancel.Value = True Then ButtonChoice =
vbOKCancel
ElseIf OptAbortRetryIgnore.Value = True Then
ButtonChoice = vbAbortRetryIgnore
ElseIf OptYesNoCancel.Value = True Then
ButtonChoice = vbYesNoCancel
ElseIf OptYesNo.Value = True Then ButtonChoice =

vbYesNo
ElseIf OptRetryCancel.Value = True Then ButtonChoice

=
vbRetryCancel

Else: MsgBox "Unexpected Error in If statement!"
End
End If

Any ideas would be greatly appreciated.
TIA

.



.