Compile Error: Else without If

Nim_26

New Member
Joined
Jun 14, 2008
Messages
13
hello all,

I've read the previous thread with the same problem but it doesn't seem to apply to my case.

I'm trying to do 3 types of average option valuation but will not burden you with the details.

Code seems to be breaking at the bolded line.

Any suggestions to what I should look at are very appreciated!

Function meth_exec() As Long

Dim comp As String: comp = Cells(18, 6).Value
Dim Av As String: Av = Cells(19, 6).Value
Dim meth As String: meth = Cells(20, 6).Value

If comp = "CN" And Av = "G" And meth = "E" Then meth_exec = 1

ElseIf comp = "DS" And Av = "A" And meth = "MC" Then meth_exec = 2

ElseIf comp = "DS" And Av = "G" And meth = "MC" Then meth_exec = 3

Else: Call not_sup

End If

End Function
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Its only because you finalised your if statements by completing the THEN condition in the same line, try this:
Code:
Function meth_exec() As Long

Dim comp As String: comp = Cells(18, 6).Value
Dim Av As String: Av = Cells(19, 6).Value
Dim meth As String: meth = Cells(20, 6).Value

If comp = "CN" And Av = "G" And meth = "E" Then
meth_exec = 1
ElseIf comp = "DS" And Av = "A" And meth = "MC" Then
meth_exec = 2
ElseIf comp = "DS" And Av = "G" And meth = "MC" Then
meth_exec = 3
Else: Call not_sup
End If

End Function
 
Upvote 0
yep yep...That sorted it out alright :)

Thank you!!!

now to sort out the other issue...

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,255
Members
448,879
Latest member
oksanana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top