Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default compile error: else without if

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default compile error: else without if

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default compile error: else without if

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


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default compile error: else without if

Hi
you also have to add a linebreak after the first Then. Try the
following:

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

If OptOKOnly.Value = True Then 'insert linebreak here
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 If
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany


papa wrote:
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


.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default compile error: else without if

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


.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default compile error: else without if

I got further in the code that time. Thank you.
What is the single line if statement translate to? What
makes it different that splitting the statement between
two lines?


-----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

.



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default compile error: else without if

A single line if statement has to all be on one line

if condition then result

or

if condition then result else other result

so you can not put any part of an if statement on another line such as an
elseif or end if because they won't match up.

the compiler sees the single line if statement as a complete command.

the comiler sees a single line if statement if there is anything after the
Then statement on the same line.

from an appearance standpoint you can do

if conditition then : result
Elseif condition then : another result
else : other result
End if

by using a command separator, but this is only for appearance. From a code
organization stantpoint, it is the same as

if condition then
result
elseif condition then
another result
else
other result
end if

--
Regards,
Tom Ogilvy



"papa" wrote in message
...
I got further in the code that time. Thank you.
What is the single line if statement translate to? What
makes it different that splitting the statement between
two lines?


-----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

.



.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default compile error: else without if

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

.



.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default compile error: else without if

Hi
change the last line form
End
to
End if

--
Regards
Frank Kabel
Frankfurt, Germany

"papa" schrieb im Newsbeitrag
...
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

.



.


  #10   Report Post  
Posted to microsoft.public.excel.programming
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

.



.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solver - error - Compile Error Nina Excel Discussion (Misc queries) 0 August 19th 08 09:41 PM
help with this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM
Compile error in hidden module error Melissa Zebrowski Excel Programming 3 February 20th 04 01:29 PM


All times are GMT +1. The time now is 01:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"