Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Check for valid national insurance number

Hi there

Does anyone have some code to check that the value in a variable is a
valid national insurance number e.g. AB123456C ?

Cheers

Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Check for valid national insurance number

Try this, based on your example

Public Function IsNatInsurNum(DataInput As Variant) As Boolean
Dim mydata As String, Temp As Long
IsNatInsurNum = False
mydata = CStr(DataInput) 'convert to string
If Len(mydata) = 9 Then 'nine characters
If (Asc(Left(mydata, 1)) = 65 And Asc(Left(mydata, 1)) <= 90)
Then 'first char is A to Z
If (Asc(Mid(mydata, 2, 1)) = 65 And Asc(Mid(mydata, 2, 1)) <=
90) Then 'second char is A to Z
On Error Resume Next
Err.Clear
Temp = CDbl(Mid(mydata, 3, 6)) 'check 6 digits in middle
If Temp < 0 Then
If (Asc(Right(mydata, 1)) = 65 And
Asc(Right(mydata, 1)) <= 90) Then 'last char is A to Z
IsNatInsurNum = True
End If
End If
On Error GoTo 0
End If
End If
End If

End Function

regards
Paul
On May 2, 10:58 am, Keith74 wrote:
Hi there

Does anyone have some code to check that the value in a variable is a
valid national insurance number e.g. AB123456C ?

Cheers

Keith



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Check for valid national insurance number

Thats great, thanks Paul

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check valid Date value? hstijnen Excel Worksheet Functions 1 August 14th 06 01:25 PM
? Link attached - How to validate SIN (Social Insurance Number) [email protected] Excel Worksheet Functions 5 December 17th 05 07:07 AM
where can i find uk tax and national insurance calculations Dr.AJ Excel Discussion (Misc queries) 1 May 17th 05 10:16 PM
check for valid file pabs[_21_] Excel Programming 2 January 15th 04 06:52 AM


All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"