1

Good morning, afternoon to everyone:

I've a statement in VBA like this one:

Select Case MAAX(Fila, 1)
    Case Is <> 5, Is <> 10, Is <> 15, Is <> 20, Is <> 25, Is <> 30, Is <> 35, Is <> 40
            Do whatever
End Select

But it's not working..What is wrong?

3
  • 2
    What do you mean by "not working"? Perhaps your understanding of the logic of that statement is incorrect. Your statement will effectively evaluate to TRUE Commented Feb 17, 2018 at 12:03
  • In future, please explain why it's not working. Give us some example data which hasn't worked and explain what it would look like if it had worked Commented Feb 17, 2018 at 12:51
  • I'm sorry Ron and CallumDA, I forgot explain the problem from my point of view.. If the fist number evaluated is 10, the statement is true Commented Feb 17, 2018 at 15:58

2 Answers 2

2

If by "not working" you mean that the statement following your CASE is always being executed, you may be misinterpreting how that statement works:

If testexpression matches ANY Case expressionlist expression, the statements following that Case clause are executed ...

Almost no matter what is in MAAX(Fila, 1), it will surely match at least one of your clauses.

You'll need to rewrite your CASE statement (or use something else), to test for the logic you really want.

If, what you really want, is that your testvalue is not any of those (5, 10, ...), you could do something like

if v<>5 and v<>10 and v<>15 ...

or, possibly

 select case v mod 5
     case is <>0  'then it is not one of those in your list, 
                  'but it could be greater than 40, so you might have to test for that
Sign up to request clarification or add additional context in comments.

3 Comments

So, in this type of expression, if the first case is TRUE, everything else doesn't mind....
@Manuel Regard your Case statement as having the test_expressions connected by OR's. So if any one of the test_expressions is true, the line following will execute.
I will do. Thanks a lot for your answer, Ron
1

See Ron's answer for a good explanation of the probem. I'd personally change your code to this:

Select Case MAAX(Fila, 1)
    Case 5, 10, 15, 20, 25, 30, 35, 40
    Case Else
        'do something
End Select

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.