VBA What's wrong?

M

Martin

If [years] >= 10 Then a9 = 4
ElseIf [years] >= 5 And [years] <= 9 Then a9 = 3
ElseIf [years] >= 2 And [years] <= 4 Then a9 = 2
ElseIf [years] < 2 Then a9 = 1
End If



What's wrong? I think, "and" is wrong, but how to solve it?
 
R

Rick Brandt

Martin said:
If [years] >= 10 Then a9 = 4
ElseIf [years] >= 5 And [years] <= 9 Then a9 = 3
ElseIf [years] >= 2 And [years] <= 4 Then a9 = 2
ElseIf [years] < 2 Then a9 = 1
End If



What's wrong? I think, "and" is wrong, but how to solve it?

What is the problem?

You dont need the "Ands" because the previous If not being satisfied has already
eliminated that possibility. All you should need is...

If [years] >= 10 Then a9 = 4
ElseIf [years] >= 5 Then a9 = 3
ElseIf [years] >= 2 Then a9 = 2
Else a9 = 1
End If
 
M

Martin

ah! Thanks! You are tops :)

Rick Brandt said:
Martin said:
If [years] >= 10 Then a9 = 4
ElseIf [years] >= 5 And [years] <= 9 Then a9 = 3
ElseIf [years] >= 2 And [years] <= 4 Then a9 = 2
ElseIf [years] < 2 Then a9 = 1
End If



What's wrong? I think, "and" is wrong, but how to solve it?

What is the problem?

You dont need the "Ands" because the previous If not being satisfied has
already eliminated that possibility. All you should need is...

If [years] >= 10 Then a9 = 4
ElseIf [years] >= 5 Then a9 = 3
ElseIf [years] >= 2 Then a9 = 2
Else a9 = 1
End If
 
Top