简体   繁体   中英

Excel Data validation drop down list from a cell

I'm kind of stuck here.

In Excel with data validation, we can make a drop down list and go something like

数据验证示例

But what if that "a, b, c, d" is populated inside a cell?

Is it possible to reference the list from that?

Say if I have a cell in A2 contains a string list by using =TEXTJOIN(",",TRUE,A1:D1) , which will populate the "a,b,c,d" as desired for the list

What/How can I do to read A2 cell value into the Source Field of the Data validation?

PS: No, do not tell me I can just use =A1:D1 in the Source field, as the actual cells I'm referencing are scattered throughout different sheets

This possible, but a bit complicated. You will need to build an XML string from your value string and then filter its elements.

In my example, all the values that should appear in the dropdown are in cell A2, separated with , :

在 Excel 中使用 FILTERXML 拆分值字符串

We use the following formula to split the values:

=FILTERXML("<t><s>"&SUBSTITUTE(A2;",";"</s><s>")&"</s></t>";"//s")

How it works

First, we build an XML string using SUBSTITUTE (we substitute , with XML tags):

="<t><s>"&SUBSTITUTE(A2;",";"</s><s>")&"</s></t>"

This will result in the following:

<t><s>apples</s><s>pears</s><s>grapes</s><s>bananas</s></t>

Using FILTERXML , we can now extract all values between the <s> elements.

Be aware that FILTERXML will automatically spill over the necessary number of cells below A5 , so be sure that there is enough space below A5.

Unfortunately, you cannot directly use this formula in the validation . But you can enter the formula in a hidden column or hidden sheet and then use a spill reference , like this one:

=A5#

溢出引用动态数组 Excel

Result

使用溢出参考在 Excel 中进行下拉验证

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM