Excel- UserForm validation coding- Please help!

  Neet_8 20:41 24 Jan 2008

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 2008

Case 32, 65 To 90, 97 To 122

  Neet_8 20:50 24 Jan 2008

Thank you! It worked.

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

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Awful clip art from 1994 is being tweeted every hour by a bot

iPhone X vs Samsung Galaxy Note 8

Les meilleurs navigateurs internet 2017