i want to create a function to check a string 0f length 10

amitnigamz

New Member
Joined
Apr 18, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
hello all !!

i want to create a function to check a string of lenght 10. Here first 5 character only alphabet i.e A-Z or a-z and then 4 character only digit i.e 0-9 and the last character must be only
alphabet i.e A-Z or a-z . I tried to solved it but could'd


# code
Function PAN_CHECK(pan_no As Variant) As Variant

'Dim pan_no As Variant
Dim pan_size As Integer
Dim input_string As Variant
Dim split_aplha, split_aplha1 As String
Dim alpha_len As Integer

input_string = pan_no

pan_size = Len(Trim(pan_no))


If input_string = "" Then

PAN_CHECK = "BLANK"


ElseIf pan_size = 10 Then

' CHECK FOR FIRST 5 WORDS ARE APLHABET

split_alpha = Left(input_string, 5)

'alpha_len = Len(split_alpha)

For alpha_len = 1 To Len(split_alpha)

If Left(slpit_alpha, alpha_len) = "" Then

PAN_CHECK = "WRONG"

ElseIf Asc(Left(slpit_alpha, alpha_len)) < 65 Or Asc(Left(slpit_alpha, alpha_len)) > 90 Then PAN_CHECK = "WRONG"

ElseIf Asc(Left(slpit_alpha, alpha_len)) < 97 Or Asc(Left(slpit_alpha, alpha_len)) > 122 Then PAN_CHECK = "WRONG"

Else

PAN_CHECK = "CORRECT"

End If

Next alpha_len

'CHECK FOR MID 4 WORDS ARE NUMBER

split_alpha = Mid(input_string, 6, 4)

For alpha_len = 1 To Len(split_alpha

If Left(slpit_alpha, alpha_len) = "" Then

PAN_CHECK = "WRONG"

ElseIf Asc(Left(split_alpha, split_len)) < 48 Then PAN_CHECK = "WRONG"

ElseIf Asc(Left(split_alpha, split_len)) > 57 Then PAN_CHECK = "WRONG"

Else

PAN_CHECK = "CORRECT"

End If

Next alpha_len

'CHECK FOR LAST 1 WORDS IS ALPHABET

split_alpha = Right(input_string, 1)

If Left(slpit_alpha, alpha_len) = "" Then

PAN_CHECK = "WRONG"

ElseIf Asc(Left(slpit_alpha, alpha_len)) < 65 Or Asc(Left(slpit_alpha, alpha_len)) > 90 Then PAN_CHECK = "WRONG"


ElseIf Asc(Left(slpit_alpha, alpha_len)) < 97 Or Asc(Left(slpit_alpha, alpha_len)) > 122 Then PAN_CHECK = "WRONG

Else
PAN_CHECK = "CORRECT"
End If

Else
PAN_CHECK = "WRONG"
End If
End Function

#code
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I would check for alphanumeric only. You can do that with something like this...

VBA Code:
Public Function IsAlphaNumericOnly(ByVal Input As Variant) As Boolean

    Dim RegEx As Object

    If IsNull(Input) = False Then
        Set RegEx = CreateObject("VBScript.RegExp")
        RegEx.Pattern = "^[a-zA-Z0-9]+$"
        IsAlphaNumericOnly = RegEx.Test(Input)
    Else
        IsAlphaNumericOnly = True
    End If

End Function

Then just call if for the first 10 characters to test it.

HTH
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top