Select Case Negative Range?

Hobbyist_programmer 621 Reputation points
2021-02-02T17:57:43.107+00:00

Hallo,

I am having trouble getting select case to work

Select Case T
                    Case > 1
                        lCol = "CP10"
                    Case 0
                        lCol = "CP0"
                    Case -2 To -4
                        lCol ="CM5"
                    Case -5 To -9
                        lCol = "CM10"
                    Case -10 To -19
                        lCol = "CM20"
                    Case -20 To -49
                        lCol = "CM40"
                    Case < -50
                        lCol = "CM50"
                End Select

If T is "-2" or negative it gives lCol is nothing error. What is wrong?

Thanks

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,749 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118.4K Reputation points
    2021-02-02T18:01:51.507+00:00

    Try specifying the smaller value first:

    . . .
    Case -4 To -2
       lCol = "CM5"
    Case -9 To -5
       lCol = "CM10"
    . . .
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Hobbyist_programmer 621 Reputation points
    2021-02-02T18:13:29.937+00:00

    thanks Viorel-1 it worked.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.