Making VBA Form TextBox accept Numbers only (including +, - and .)

后端 未结 7 1230
生来不讨喜
生来不讨喜 2020-12-01 21:46

I have simple textBox and I want to validate its input including \"+\" , \"-\" and \".\" here is what I have tried

Private Sub DisplayValue_TextBox_Change()         


        
7条回答
  •  不思量自难忘°
    2020-12-01 22:23

    If TextBox1.Value <> "" Then
        Dim N As Boolean
        N = True
        Do While N
            If Not IsNumeric(TextBox1.Value) Then
                TextBox1.Value = Left(TextBox1.Value, Len(TextBox1.Value) - 1)
            Else
                N = False
            End If
        Loop
    End If
    

提交回复
热议问题