Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

validation - Excel: how ensure cells contain numbers 1-6 or comma separated numbers 1-6?

I have question and answer spreadsheets with up to a couple hundred rows in them. One column in each row indicates a correct answer by entering a number from 1 to 6 or multiple answers separated by commas like 1,3,5. I'd like to enforce this rule on every row and not allow input of anything else.

I find can't a way to use Custom Data Validation and am not sure how to use a function in each row.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • Select your range of interest, for example A1:A10

  • Add the following formula as a custom data validation:

    =IFERROR(FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s[preceding::*=.  or .*0!=0 or .*1>6 or .*1<1]"),"")=""
    

You'd need Excel2013 onwards but the formula will validate the string value to have:

  • No duplicate values.
  • No values other than numbers.
  • No values above 6.
  • No values below 1.
  • Only comma will work as a valid seperator.

The A1 in the formula is relative so validation for A10 will work just the same way but then for A10 obviously.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...