VBA What's wrong?

  • Thread starter Thread starter Martin
  • Start date Start date
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?
 
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
 
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
 

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

Back
Top