Error message when a numeric char is entered in userform

Dinictus

Board Regular
Joined
Mar 19, 2002
Messages
162
Hey,

Got a userform in which people can submit certain codes. The data from the different textboxes is copied to certain cells in the integer format. (I have to import this data in SAS later on so I need this format)

If I type a letter, I get a type mismatch and the debugger starts. I just want an error message like: only numeric values are allowed.

Here is the syntaxt for 1 textbox:
Anyone who can give me a clue?

Private Sub TBpanel_Change()
Worksheets("sheet1").Range("A2").Value = Int(TBpanel)

This doesn`t work:
'If Not IsNumeric(TBpanel.Value) Then
' MsgBox "Alleen numerieke data is toegestaan", vbExclamation, "Invalid Entry"
'End If

End Sub

Cheers,

Dinictus.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello,

The problem is because you're trying to convert the TBPanel's value to an integer before you've checked whether or not it is numeric. Check first, and then assign it to the worksheet and you'll be fine.

Code:
Private Sub TBpanel_Change()
If IsNumeric(TBPanel.Value) = True Then
    Worksheets("sheet1").Range("A2").Value = Int(TBPanel)
Else
    MsgBox "Alleen numerieke data is toegestaan", vbExclamation, "Invalid Entry"
End If
End Sub
 
Upvote 0
DK!!

Thanks for taking the time to read my issue. You were defenitely right.

great, it is much appreciated.

Cheers,
 
Upvote 0
You need to change the order of your code because it is failing when you try to put a non integer value on sheet1.

This will work:

Private Sub TBpanel_Change()
If Not IsNumeric(TBpanel.Value) Then
MsgBox "Alleen numerieke data is toegestaan", vbExclamation, "Invalid Entry"
Exit Sub
End If
Worksheets("sheet1").Range("A2").Value = Int(TBpanel)
End Sub

However, this is putting the value on sheet1 one character at a time. It would probably be better to move the validation to the OK Button Click event handler.
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,638
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top