# Compile Error: Else without If

#### Nim_26

##### New Member
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying

#### Simon Lloyd

##### Well-known Member
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``````

#### Nim_26

##### New Member
yep yep...That sorted it out alright

Thank you!!!

now to sort out the other issue...

Thanks again!

Replies
3
Views
764
Replies
4
Views
339
Replies
1
Views
336
Replies
6
Views
462
Replies
5
Views
290

1,191,218
Messages
5,985,325
Members
439,958
Latest member
qb0000

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

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