select case is not working

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,556
Hi
Why when I enter 66 as a number, this code print "Else"?
it does not go the first case? any idea why? I used F8 but again jump to the last case.
Thank you very much.
Code:
Sub test3()
    Dim x As Integer
    x = InputBox("enter number")
    Select Case x
        Case x > 50
            MsgBox ">50"
        Case x < 30
            MsgBox "<30"
        Case Else
            MsgBox "else"
    End Select
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,909
Office Version
365
Platform
Windows
Either use
Code:
Sub test3()
    Dim x As Integer
    x = InputBox("enter number")
    Select Case True
        Case x > 50
            MsgBox ">50"
        Case x < 30
            MsgBox "<30"
        Case Else
            MsgBox "else"
    End Select
End Sub
or
Code:
Sub test3()
    Dim x As Integer
    x = InputBox("enter number")
    Select Case x
        Case Is > 50
            MsgBox ">50"
        Case Is < 30
            MsgBox "<30"
        Case Else
            MsgBox "else"
    End Select
End Sub
 

Forum statistics

Threads
1,085,955
Messages
5,386,925
Members
402,025
Latest member
saresum

Some videos you may like

This Week's Hot Topics

Top