ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   compile error: else without if (https://www.excelbanter.com/excel-programming/293814-compile-error-else-without-if.html)

papa[_2_]

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

Frank Kabel

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



papa[_2_]

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


.


Frank Kabel

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


.



Tom Ogilvy

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


.




papa[_3_]

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

.



.


Tom Ogilvy

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

.



.




papa[_3_]

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

.



.


Frank Kabel

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

.



.



Jeff Meeko

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

.



.




No Name

compile error: else without if
 
I didn't get that line copied, but an end if does exist on
the next line (that I did not paste).


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

.



.


.


Frank Kabel

compile error: else without if
 
Hi
then delete the End statement. No reason for this statement at this
point. It will stop the macro execution.

--
Regards
Frank Kabel
Frankfurt, Germany

schrieb im Newsbeitrag
...
I didn't get that line copied, but an end if does exist on
the next line (that I did not paste).


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

.



.


.



papa[_4_]

compile error: else without if
 
Frank,
I have removed the end and the same thing happens. It
appears that the code is not progressing beyond the first
If then statement as the following is highlighted upon the
break.

If optCritial.Value = True Then

iconchoice = vbCritical


-----Original Message-----
Hi
then delete the End statement. No reason for this

statement at this
point. It will stop the macro execution.

--
Regards
Frank Kabel
Frankfurt, Germany

schrieb im

Newsbeitrag
...
I didn't get that line copied, but an end if does exist

on
the next line (that I did not paste).


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

.



.


.


.


Frank Kabel

compile error: else without if
 
Hi
what is your exact error message?

--
Regards
Frank Kabel
Frankfurt, Germany

"papa" schrieb im Newsbeitrag
...
Frank,
I have removed the end and the same thing happens. It
appears that the code is not progressing beyond the first
If then statement as the following is highlighted upon the
break.

If optCritial.Value = True Then

iconchoice = vbCritical


-----Original Message-----
Hi
then delete the End statement. No reason for this

statement at this
point. It will stop the macro execution.

--
Regards
Frank Kabel
Frankfurt, Germany

schrieb im

Newsbeitrag
...
I didn't get that line copied, but an end if does exist

on
the next line (that I did not paste).


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

.



.


.


.



JWolf

compile error: else without if
 
Option explicit?
optCritial or optCritical?

papa wrote:
Frank,
I have removed the end and the same thing happens. It
appears that the code is not progressing beyond the first
If then statement as the following is highlighted upon the
break.

If optCritial.Value = True Then

iconchoice = vbCritical



-----Original Message-----
Hi
then delete the End statement. No reason for this


statement at this

point. It will stop the macro execution.

--
Regards
Frank Kabel
Frankfurt, Germany

schrieb im


Newsbeitrag

.. .

I didn't get that line copied, but an end if does exist


on

the next line (that I did not paste).



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

.



.


.


.


No Name

compile error: else without if
 
THAT'S IT! Thank you. It took me a minute to see the
difference even in your post. I need to learn to
transpose characters.

THANK YOU Frank and JWOLF


-----Original Message-----
Option explicit?
optCritial or optCritical?

papa wrote:
Frank,
I have removed the end and the same thing happens. It
appears that the code is not progressing beyond the

first
If then statement as the following is highlighted upon

the
break.

If optCritial.Value = True Then

iconchoice = vbCritical



-----Original Message-----
Hi
then delete the End statement. No reason for this


statement at this

point. It will stop the macro execution.

--
Regards
Frank Kabel
Frankfurt, Germany

schrieb im


Newsbeitrag

. ..

I didn't get that line copied, but an end if does

exist

on

the next line (that I did not paste).



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

l...

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

.



.


.


.

.


JWolf

compile error: else without if
 
Start all your modules with the line: Option Explicit or in the VBA
editor check the box under Tools, Options, Editor tab, Require Variable
Declaration and Excel will automatically insert Option Explicit in each
module. Then you must declare all variables with a Dim statement. Any
subsequent misspellings will cause a Compile error: Variable not defined
which alerts you to the misspellings. Declaring all variables may seem
like a pain and a waste of time, but after a few compile errors you will
see the value of requiring all variables to be declared.

wrote:
THAT'S IT! Thank you. It took me a minute to see the
difference even in your post. I need to learn to
transpose characters.

THANK YOU Frank and JWOLF



-----Original Message-----
Option explicit?
optCritial or optCritical?

papa wrote:



All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com