Help with code error.

C

Cam

Duane,

I have the following code and it gave me the error below. What do I need to
do to fix the code? The code looks at three different scenerio and return the
calculated result based on the scenerio. Thanks

Public Function MyCalc(O As Integer, P As Integer, _
H As Double, I As Double, J As Double, K As Double, _
L As Double, M As Double, Q As Double, N As Double) As Variant

Dim varReturn As Variant
If O = 1 And P = 2 Then
varReturn = (((H + I) / 60) / L) + (J * (1 - M)) / N
Else
If O = 2 And P = 1 Then
varReturn = (((H + I) / 60) / K) + (J * (1 - M)) / N
Else
If O = 1 And P = 1 Then
varReturn = (((H + I) / 60) * Q + (J * (1 - M))) / N

End If

MyCalc = varReturn

End Function


"Compile error:
Block If without End If"
 
P

pietlinden

Duane,

I have the following code and it gave me the error below. What do I need to
do to fix the code? The code looks at three different scenerio and returnthe
calculated result based on the scenerio. Thanks

Public Function MyCalc(O As Integer, P As Integer, _
    H As Double, I As Double, J As Double, K As Double, _
    L As Double, M As Double, Q As Double, N As Double) As Variant
    Dim varReturn As Variant
    If O = 1 And P = 2 Then
        varReturn = (((H + I) / 60) / L) + (J * (1 - M)) / N
    ElseIf O = 2 And P = 1 Then
            varReturn = (((H + I) / 60) / K) + (J * (1 - M))/ N
    ElseIf O = 1 And P = 1 Then
            varReturn = (((H + I) / 60) * Q + (J * (1 - M)))/ N
End If
    MyCalc = varReturn

End Function

"Compile error:
Block If without End If"

because you're missing two End Ifs. try that...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top