Results 1 to 2 of 2

Thread: select case is not working
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Mar 2016
    Posts
    1,436
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default select case is not working

    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

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,120
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: select case is not working

    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
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •