VBA Select case 1 to 100 只取1

VBA Select case 1 to 100 only taking 1

我正在尝试创建一个 select 案例来识别数字是否小于 0、1 到 100 或大于 100,但问题是这不起作用。这是我的代码:

If IsNumeric(TxtTemp.Text) Then

    Select Case TxtTemp.Text

        Case Is <= 0
            TxtEstado.Text = "Solid"

        Case 1 To 100
            TxtEstado.Text = "Liquid"

        Case Is > 100
            TxtEstado.Text = "Gas"

    End Select

Else

TxtEstado.Text = ""

End If

我知道这很容易做到,问题是 select 案例 returns 液体仅当收到的数字等于 1 时。如果它小于或等于0 它 returns 固体,但如果它等于或大于 2,它 returns 气体。我不明白我做错了什么。

也许这种转换使用函数更容易

    Function chText(txt As String) As String

    On Error GoTo EH

        Dim resTxt As String

        If IsNumeric(txt) Then
            Select Case CDbl(txt)
                Case Is <= 0
                    resTxt = "Solid"
                Case 1 To 100
                    resTxt = "Liquid"
                Case Is > 100
                    resTxt = "Gas"
            End Select
        Else
            resTxt = ""
        End If

        chText = resTxt

        Exit Function

    EH:
        chText = "Error"

    End Function

Sub Tester()

 Debug.Print chText("101")
' TxtEstado.Text = chText(TxtTemp.Text)

End Sub