问题
I know the data validation only lets you place 255 characters. I have named cells/ranges as I have several list I'm trying to pull or select certain information from based on a criteria. My formula is as follows:
=IF(AND(RETAILER="",DISPLAY_TYPE=""),"",IF(AND(RETAILER=CODES!$F$2,(OR(DISPLAY_TYPE=CODES!$V$1,DISPLAY_TYPE=CODES!$Y$1))),CODES!$V$2:$V$49,IF(AND(RETAILER=CODE S!$F$2,(OR(DISPLAY_TYPE=CODES!$AB$1,DISPLAY_TYPE=CODES!$AE$1))),CODES!$AB$2:$AB$94,IF(AND(RETAILER=CODES!$F$3,(OR(DISPLA Y_TYPE=CODES!C1,DISPLAY_TYPE=CODES!C2,DISPLAY_TYPE=CODES!C3,DISPLAY_TYPE=CODES!C4))),"INCORRECT COMBINATION, Correct Retailer or Display Type",IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AH1),CODES!AH2:AH38,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AJ1),CO DES!AJ2:AJ10,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AL1),CODES!AL2:AL18,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=C ODES!AN1),CODES!AN2:AN18,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AP1),CODES!AP2:AP18,IF(AND(RETAILER=CODES!$F$3,DI SPLAY_TYPE=CODES!AR1),CODES!AR2:AR29,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AT1),CODES!AT2:AT29,IF(AND(RETAILER=C ODES!$F$2,(OR(DISPLAY_TYPE=CODES!C5,DISPLAY_TYPE=CODES!C6,DISPLAY_TYPE=CODES!C7,DISPLAY_TYPE=CODES!C8,DISPLAY_TYPE=CODES !C9,DISPLAY_TYPE=CODES!C10,DISPLAY_TYPE=CODES!C11))),"INCORRECT COMBINATION, Change Retailer or Display Type",""))))))))))))
I know, too long for data validation, so, I then tried to "name" my formula by choosing a cell where my formula is nested (hit CTRL+F3, named the cell CHECK_FORMULA) and placed the above formula in the "refers to" box. Then, I went to C21 (where I want to have my data validation) and entered the following:
=IF(OR(RETAILER="",DISPLAY_TYPE=""),"INVALID",CHECK_FORMULA)
The error that I receive, " The list source must be a delimited list, or reference to a single row or column". The formula provides a set list of parts depending on the criteria set that will show. I didn't have this issue when the formula was under 255 characters, chose the list according to criteria, no problem, but now, because other list were added, I'm having this issue. Is there a macro I can put this into in order to accomplish my goal? or can I use CASE in a way to get what I'm trying to accomplish?
回答1:
I think that data validation does not play nice with named ranges. Try using the INDIRECT formula.
=IF(OR(INDIRECT("RETAILER")="",INDIRECT("DISPLAY_TYPE")=""),"INVALID",INDIRECT("CHECK_FORMULA"))
回答2:
SOLVED....I placed the formula in a named range and it worked after I applied a "fix" to my Excel (issued by Microsoft): The name range 'CheckFormula' works with the following:
=`IF(AND(RETAILER="",DISPLAY_TYPE=""),"",IF(AND(RETAILER=CODES!$F$2,(OR(DISPLAY_TYPE=CODES!$V$1,DISPLAY_TYPE=CODES!$Y$1))),CODES!$V$2:$V$47,IF(AND(RETAILER=CODES!$F$2,(OR(DISPLAY_TYPE=CODES!$AB$1,DISPLAY_TYPE=CODES!$AE$1))),CODES!$AB$2:$AB$72,IF(AND(RETAILER=CODES!$F$3,(OR(DISPLAY_TYPE=CODES!C1048575,DISPLAY_TYPE=CODES!C1048576,DISPLAY_TYPE=CODES!C1,DISPLAY_TYPE=CODES!C2))),"INCORRECT COMBINATION, Correct Retailer or Display Type",IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AH1048575),CODES!AH1048576:AH36,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AJ1048575),CODES!AJ1048576:AJ8,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AL1048575),CODES!AL1048576:AL16,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AN1048575),CODES!AN1048576:AN16,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AP1048575),CODES!AP1048576:AP16,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AR1048575),CODES!AR1048576:AR27,IF(AND(RETAILER=CODES!$F$3,DISPLAY_TYPE=CODES!AT1048575),CODES!AT1048576:AT27,IF(AND(RETAILER=CODES!$F$2,(OR(DISPLAY_TYPE=CODES!C3,DISPLAY_TYPE=CODES!C4,DISPLAY_TYPE=CODES!C5,DISPLAY_TYPE=CODES!C6,DISPLAY_TYPE=CODES!C7,DISPLAY_TYPE=CODES!C8,DISPLAY_TYPE=CODES!C9))),"INCORRECT COMBINATION, Change Retailer or Display Type",""))))))))))))`
Thank you to all those who provided assistance.
来源:https://stackoverflow.com/questions/28157197/excel-vba-assistance-data-validation-too-long-need-alternative