Hi
I have this code for validating a national insurance number but how do i assign this to a cell in excel.
Thanks for the helpPlease Login or Register to view this content.
Simon
Hi
I have this code for validating a national insurance number but how do i assign this to a cell in excel.
Thanks for the helpPlease Login or Register to view this content.
Simon
You may want to think about applying via a Worksheet_Change event, eg:
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.Please Login or Register to view this content.
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.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
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.
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
Presumably because when you're applying it the cell does not contain an NI number...........just click Yes on prompt....the formula you left evaluates to an error
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.
Attached...
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
What if you want the code to appy to a whole column?
How can i manipulate the code then?
Help would be much appreciated
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks