tomi09pl
tomi09pl

Reputation: 58

Excel VBA - Select Case with comparison

I've got simple Select Case statement which doesn't work as intended.

I want to do different actions depending on my value being greater or equal to 1 or being less than 1.

When myValue is declared as Double procedure doesn't find a match (nothing is returned), when myValue is declared as Long it returns the first case "more than 1" - where this is incorrect as myValue is set to 0.5 ...

Can somebody tell me what I'm missing?

Public Sub test()

    Dim myValue As Double
    
    myValue = 0.5

    
    Select Case myValue
    
        Case myValue >= 1
            Debug.Print "more than 1"
        Case myValue < 1
            Debug.Print "less than 1"
    
    End Select

End Sub

Upvotes: 1

Views: 297

Answers (1)

Gustav
Gustav

Reputation: 56026

Use the correct syntax:

Public Sub test()

    Dim myValue As Double
    
    myValue = 0.5
    
    Select Case myValue
        Case Is >= 1
            Debug.Print "more than 1"
        Case Is < 1
            Debug.Print "less than 1"
    End Select

End Sub

Upvotes: 1

Related Questions