im trying to check if a number is a text or number in a banking system. If the value is incorrect it should erase and send an error message, but my code isnt working at all… can someone help me? here is the code:
Private Sub TextBox1_Change()
name = TextBox1
If Application.IsText(name) = True Then
IsText = True
Else
MsgBox "Insert only words"
Selection.name.Delete
End If
End Sub
I think you should be using
name = TextBox1.Textinstead. It’s probably giving you an error on that line.Also, you may want to wait until the user is finished typing the response, I believe the changed event will run each time a character is pressed. The
AfterUpdatewill run after you tab or click away from the textbox.And really, instead of deleting the response (which I don’t think will work), you should simply set the textbox blank back to an empty string.
I’m sure the code could be structured better, but there’s something along the lines of what you need. In this case, it just wipes the textbox if there is a number entered. Obviously, things will need to be the opposite for your textbox that you want to contain a number.