Excel- UserForm validation coding- Please help!

  Neet_8 20:41 24 Jan 08

Hello, I have created a small system in Microsoft Excel which has a UserForm in it. The user form comprises of various text boxes, in which it is necessary that they have validation coding (Visual Basic Editor) to prevent numerical data being inserted into the text boxes.

I have inserted the coding below but was wondering how i could change this coding so that it also allows spaces to be inserted between words, as currently when the space bar is pressed, the set message box appears not allowing the space to be made. The coding is as follows:

Private Sub CustomerName_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
' this code only allows text to be enterd into the textbox
Dim keyval As Integer
keyval = KeyAscii.Value
Select Case keyval
Case 65 To 90, 97 To 122
Exit Sub
End Select
MsgBox ("Numeric data cannot be inserted into this field- Please insert text only")
SendKeys "{backspace}"
End Sub

Your help would very much be appreciated. Thank you!

  VoG II 20:44 24 Jan 08

Case 32, 65 To 90, 97 To 122

  Neet_8 20:50 24 Jan 08

Thank you! It worked.

This thread is now locked and can not be replied to.

What is ransomware and how do I protect my PC from WannaCry?

What I learned from my mentor, Oscar-winning VFX supervisor Phil Tippett

Siri vs Google Assistant