Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As part of a macro, I open an input box. Here is the part I'm not sure how
to code: I'd like the input to be restricted to either 1 or 2 alphanumeric characters ONLY. (no spaces, other symbols, =3 characters, etc.) 1, Ab, 4G, are all OK. #4, 1 2, A3b are not OK. Could someone offer a few clues? Thanks Bri |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I wouldn't use an input box - use a user form, which has keypress
events - which means you can restrict the key's being pressed by code. You can also restrict the input length to the two characters you want. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ok, good suggestion, but I still am not sure how to code that. any clues"
Bri wrote in message oups.com... I wouldn't use an input box - use a user form, which has keypress events - which means you can restrict the key's being pressed by code. You can also restrict the input length to the two characters you want. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
assuming to use input box, i'm not sure this one would satisfy you. but
try this. Sub testme() Dim strprompt As String Dim flg As Boolean Dim sdata As String Dim res strprompt = "input only alphanumeric" flg = True sdata = "0123456789abcdefghijklmnopqrstuvwxyz" Do While flg res = Application.InputBox(strprompt, _ Default:=res, Type:=3) If VarType(res) = vbBoolean Then Exit Sub ElseIf Len(res) = 1 Then If InStr(sdata, Left(LCase(res), 1)) _ 0 Then flg = False Else strprompt = _ "Wrong Data!! Not alphanumeric" End If ElseIf Len(res) = 2 Then If InStr(sdata, Left(LCase(res), 1)) 0 _ And InStr(sdata, Right(LCase(res), 1)) _ 0 Then strprompt = "Wrong Data!!" flg = False Else strprompt = _ "Wrong Data!! Not alphanumeric" End If Else strprompt = _ "Wrong Data!! Too many characters" End If Loop MsgBox res End Sub "Bri" wrote in message ... As part of a macro, I open an input box. Here is the part I'm not sure how to code: I'd like the input to be restricted to either 1 or 2 alphanumeric characters ONLY. (no spaces, other symbols, =3 characters, etc.) 1, Ab, 4G, are all OK. #4, 1 2, A3b are not OK. Could someone offer a few clues? Thanks Bri |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Insert a user form into your module
Insert a text box - use the properties to set maxlength at 2 in code use Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii < 48 Or KeyAscii 122 Then KeyAscii = 0 If KeyAscii 57 And KeyAscii < 65 Then KeyAscii = 0 If KeyAscii 90 And KeyAscii < 97 Then KeyAscii = 0 End Sub This will allow upper and lower case and numbers ONLY, and a maximum length of 2 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Restricting Number of characters in a cell | Excel Worksheet Functions | |||
Restricting Characters within a User Form | Excel Discussion (Misc queries) | |||
restricting use of certain characters | Excel Discussion (Misc queries) | |||
Restricting Characters in a cell. | Excel Programming | |||
Restricting User Input... | Excel Programming |