Some simple VBA questions:
This is for a Quantitative Finance class, we have only been introduced to VBA for Excel, so this isn't hard and I can't see for the life of me what I'm doing wrong.
First of all, when I paste an example from the text into VBA I get a "Compile Error: Else without If" error:
Function gpa(s)
If s < 75 Then
gpa = 2
Else If s < 88 Then
gpa = 3
Else
gpa = 4
End If
End Function
This is supposed to be correct as per the text so maybe I need to change a setting? The function I am to write for homework looks correct following the book's instructions:
Function fedtax(x)
If x < 7300 Then fedtax = 0.1 * x
ElseIf x < 29700 Then fedtax = 730 + 0.15 * (x - 7300)
ElseIf x < 71950 Then fedtax = 4090 + 0.25 * (x - 29700)
ElseIf x < 150150 Then fedtax = 14652.5 + 0.28 * (x - 71950)
ElseIf x < 326450 Then fedtax = 36548.5 + 0.33 * (x - 150150)
Else: fedtax = 94727.5 + 0.35 * (x - 326450)
End Function
if I write a very simple if function, it turns out fine:
Function fedtax(x)
If x < 7300 Then fedtax = 0.1 * x
End If
End Function
I also tried the 2nd function using Else: If instead of ElseIf but got the same error. I appreciate any help on the matter, thanks for reading!
This is for a Quantitative Finance class, we have only been introduced to VBA for Excel, so this isn't hard and I can't see for the life of me what I'm doing wrong.
First of all, when I paste an example from the text into VBA I get a "Compile Error: Else without If" error:
Function gpa(s)
If s < 75 Then
gpa = 2
Else If s < 88 Then
gpa = 3
Else
gpa = 4
End If
End Function
This is supposed to be correct as per the text so maybe I need to change a setting? The function I am to write for homework looks correct following the book's instructions:
Function fedtax(x)
If x < 7300 Then fedtax = 0.1 * x
ElseIf x < 29700 Then fedtax = 730 + 0.15 * (x - 7300)
ElseIf x < 71950 Then fedtax = 4090 + 0.25 * (x - 29700)
ElseIf x < 150150 Then fedtax = 14652.5 + 0.28 * (x - 71950)
ElseIf x < 326450 Then fedtax = 36548.5 + 0.33 * (x - 150150)
Else: fedtax = 94727.5 + 0.35 * (x - 326450)
End Function
if I write a very simple if function, it turns out fine:
Function fedtax(x)
If x < 7300 Then fedtax = 0.1 * x
End If
End Function
I also tried the 2nd function using Else: If instead of ElseIf but got the same error. I appreciate any help on the matter, thanks for reading!