kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
I have tried to reverse engineer a vba script to produce the code below here which allows for only alphabets and the characters listed.
I want to stop repeated characters of "-", "." or " " being entered. That's :
1. Don't allow "--", ".." or " "
2. "A-B-","A.B." or "A B " is allowed.
3. Don't allow "A -" , "A- " or "A - ". That is, if a hyphen follows a space immediately, remove the space. So "A -" becomes "A-".
And if a space immediately follows a hyphen, remove the space.
So "A- " becomes "A-"
4. After a dot, if I press any key other than the space key and there is no space after the dot, then add a space before registering the pressed key. But if the pressed key is the hyphen, no space should be added.
I know this is very complex to me. But I believe some got answers over here.
Thanks for reading.
Regards
Kelly
Code:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With TextBox1
Select Case KeyAscii
Case Asc("a") To Asc ("z")
Case Asc("A") To Asc ("Z")
Case Asc("-")
Case Asc(".")
Case Asc(" ")
Case Else: KeyAscii =0
End Select
End With
End Sub
I want to stop repeated characters of "-", "." or " " being entered. That's :
1. Don't allow "--", ".." or " "
2. "A-B-","A.B." or "A B " is allowed.
3. Don't allow "A -" , "A- " or "A - ". That is, if a hyphen follows a space immediately, remove the space. So "A -" becomes "A-".
And if a space immediately follows a hyphen, remove the space.
So "A- " becomes "A-"
4. After a dot, if I press any key other than the space key and there is no space after the dot, then add a space before registering the pressed key. But if the pressed key is the hyphen, no space should be added.
I know this is very complex to me. But I believe some got answers over here.
Thanks for reading.
Regards
Kelly
Last edited: