Report

User Friendly Code for Admission No [Solved]

Ask a question smuneeb 76Posts Saturday September 5, 2015Registration date October 12, 2016 Last seen - Last answered on Jan 26, 2016 10:33PM
Hello,

I would like to request to Code for Admission No
Range is started from B11 to B510
If user enter a123456789 or a-123456789 it always converted into
A-123456789
[A-Z] {1} First Character must be any alphabet in UPPER CASE between A to Z and max strength is 1
[-] {1} After first character Hyphen symbol must be shown and max strength is 1
[0-9] {1 to 9} after hyphen symbol any numeric character between 0 to 9 where min strength could be 7 and max strength could be 9.

Thanks & Regards
See more 
Helpful
+1
moins plus
Isn't this the same question as this?:

http://ccm.net/forum/affich-861038-difficult-query#p861975
smuneeb 76Posts Saturday September 5, 2015Registration date October 12, 2016 Last seen - Jan 20, 2016 07:29AM
Hi TrowaD
It is similar but the solution is not user friendly its a formula, and its not valuable when user is enter in B column where range is fixed B11 to B 510.
I am not demotivating your solution, you create it with your concept which is appreciable.

Thanks
Reply
Add comment
Helpful
+1
moins plus
Hi Smuneeb,

Good to see you find this user friendly.

How about this code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B11:B510")) Is Nothing Then Exit Sub
If Target.Value = vbNullString Then Exit Sub

If InStr(1, Target.Value, "-") = 2 And Len(Target.Value) >= 9 And Len(Target.Value) <= 11 Then
    If StrComp(Left(Target.Value, 1), UCase(Left(Target.Value, 1)), vbBinaryCompare) = 0 Then Exit Sub
    Target = UCase(Target.Value)
    Exit Sub
ElseIf InStr(1, Target.Value, "-") <> 2 And Len(Target.Value) >= 8 And Len(Target.Value) <= 10 Then
    Target = UCase(Left(Target.Value, 1)) & "-" & Right(Target.Value, Len(Target.Value) - 1)
Else
    Target.Value = vbNullString
    MsgBox "This is not a valid entry."
End If
End Sub


Best regards,
Trowa
smuneeb 76Posts Saturday September 5, 2015Registration date October 12, 2016 Last seen - Jan 26, 2016 10:33PM
Hi Trowa
You are great thanks for cooperation and excellent job
Best Regards
Muneeb
Reply
Add comment
Helpful
+0
moins plus
Hi Smuneeb,

Then why didn't you let me know in the other post?

You can try the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B11:B510")) Is Nothing Then Exit Sub

If InStr(1, Target.Value, "-") = 2 Then
    If StrComp(strFirst, UCase(strFirst), vbBinaryCompare) = 0 Then Exit Sub
    Target = UCase(Target.Value)
    Exit Sub
Else
    Target = UCase(Left(Target.Value, 1)) & "-" & Right(Target.Value, Len(Target.Value) - 1)
End If
End Sub


Best regards,
Trowa
smuneeb 76Posts Saturday September 5, 2015Registration date October 12, 2016 Last seen - Jan 23, 2016 03:17PM
Hi Trowa
Your code is user friendly but please make one more addition as per my request in posted query that after hyphen symbol if the length of numeric character length (not alpha character length i.e. no alpha character is applied after hyphen symbol) is between 7 and 9 then it changes to requirement else it shows an error message.

Thanks
Reply
Add comment

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!