| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 21295 | 2002-06-22 07:08:00 | Excel VBA Code - enforce letters | parry (27) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 56351 | 2002-06-22 07:08:00 | Hi, I am writing a error handler procedure for Excel2000 and need to ensure that the value of a textbox is a letter. So far I have the following:- if userform1.textbox1.value ??????????? then errorhandler=true (meaning value wasnt a letter) Could someone please help with filling in the ???? part. Dont know how to describe letters. Have tried <> a:z , <> a to z etc etc but no joy :-( cheers |
parry (27) | ||
| 56352 | 2002-06-22 11:12:00 | Try this "^[a-zA-Z]" www.aspzone.com |
Marty2001 (421) | ||
| 56353 | 2002-06-23 13:15:00 | Interesting, never heard of using a ^ for that, only for exponents. Unfortunately it doesnt recognise a letter as a valid value so will have to go back to the drawing board. The textbox value is limited to one character and is a string but i presume thats got nothing to do why it's not working. Thanks anyway. |
parry (27) | ||
| 56354 | 2002-06-24 00:12:00 | The following routine will do as required. Private Sub textBox1_CHANGE() Dim iChar As Integer Dim THETEXTBOX As String For iChar = Len(TextBox1.Value) To 1 Step -1 Select Case Mid(TextBox1.Value, iChar, 1) Case "A" To "Z", "a" To "z" Case Else MsgBox "Alpha only" TextBox1.Value = "" THETEXTBOX = Left(TextBox1.Value, iChar - 1) Exit For End Select Next End Sub HTH |
Russell D (18) | ||
| 56355 | 2002-06-24 08:02:00 | Superb, you da man!! Very clever, thanks very much. cheers Parry. |
parry (27) | ||
| 1 | |||||