+ Reply to Thread
Results 1 to 9 of 9

National Insurance Validation

  1. #1
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    National Insurance Validation

    Hi

    I have this code for validating a national insurance number but how do i assign this to a cell in excel.
    Please Login or Register  to view this content.
    Thanks for the help
    Simon

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: National Insurance Validation

    You may want to think about applying via a Worksheet_Change event, eg:

    Please Login or Register  to view this content.
    Right Click on Tab to which the validation is to be applied and select View Code, paste the above into resulting window - change the Range (in red) to be that to which the Validation is to be applied.

    You could if you wanted to shorten the Function via Regular Expressions... but if you're comfortable with what you have you should keep it.

    I'm not aware of a way in which a custom UDF can be called directly from within Custom Data Validation formula... you may be able to... I can't answer definitively.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: National Insurance Validation

    I should add that you could of course revert to a standard Custom Validation Formula approach, eg if B3 is first cell of interest then highlight B3 and set up Validation -> Custom: Formula:

    =AND(AND(CODE(LEFT(B3,1))>=65,CODE(LEFT(B3,1))<=90),AND(CODE(MID(B3,2,1))>=65,CODE(MID(B3,2,1))<=90),AND(CODE(RIGHT(B3,1))>=65,CODE(RIGHT(B3,1))<=90),ISNUMBER(0+MID(B3,3,6)))

    Then you can dispense with UDF / VBA altogether.

  4. #4
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    Re: National Insurance Validation

    Thanks for the response.

    I like the idea of using the custom validation over vb, but the formula you left evaluates to an error.

    If this is not simple to amend then i will go with other method,

    Thanks again

    Simon

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: National Insurance Validation

    ...the formula you left evaluates to an error
    Presumably because when you're applying it the cell does not contain an NI number...........just click Yes on prompt.

  6. #6
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    Re: National Insurance Validation

    when i apply The validation i get the popup saying currently evaluates to an error. So i carried on as normal but I am able to enter any value into the cell it's not validating as it should.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: National Insurance Validation

    Attached...
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    Re: National Insurance Validation

    thats great thank you it took me a while to figure out that it was capitals with no spaces but thats just how i wanted it .

    thanks again

    Simon

  9. #9
    Registered User
    Join Date
    06-29-2012
    Location
    England
    MS-Off Ver
    Excel 2003,07
    Posts
    1

    Re: National Insurance Validation

    What if you want the code to appy to a whole column?

    How can i manipulate the code then?

    Help would be much appreciated

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1