View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
David G[_4_] David G[_4_] is offline
external usenet poster
 
Posts: 23
Default Validation based on digits in the middle of a string

On Apr 20, 2:02 pm, TexasStar wrote:
Is it possible to perform this validation on the three digits in the
middle of the string 30-015-00745 and if so how might I go about
doing that validation?


You can add data validation to your cells from Data Validation...
Specify Custom validation type and use a formula along the lines of:
=AND(NOT(ISERROR(SEARCH("-???-",A1))),NOT(ISNA(MATCH(MID(A1,SEARCH("-???-",A1)+1,3),validlist,
0))))
Where A1 needs to be changed to the address of the cell to be
validated.

Quick explanation:
1. SEARCH finds the index of the middle section in the string format
you specified
2. MID cuts out the 3 characters between the -'s
3. MATCH tried to find that value in the list you specified. It
returns #N/A if the value is not found

Be sure to provide a more specific error message than the default data
validation error message, or the users will go crazy.

Good luck,
David