Excel VBA UserForm TextBox - Check If Input Is a Number or Not (on button click)

Опубликовано: 06 Октябрь 2024
на канале: InAnOffice
7,968
36

Excel VBA UserForm TextBox - Learn how to check if input is a number or not (on button click)

The code used in this video:

Private Sub cbOk_Click()

If Not IsNumeric(txtPrice) Then
MsgBox "Please enter a valid number", vbCritical

With txtPrice
.SelStart = 0
.SelLength = Len(txtPrice)
.SetFocus
End With

Exit Sub
End If

MsgBox "Price OK"

End Sub