How to use VLOOKUP to split multiple-valued cell into separate rows?

匆匆过客 提交于 2020-06-01 07:12:11

问题


As the title says, how do you split this

into


回答1:


Not sure where the VLOOKUP comes from in your question, but if you have Excel 2010 or later you can do this through PowerQuery

  • Select your data
  • Data tab > From Table/Range
  • You have headers, so choose accordingly

PowerQuery should now start, and within the opened tab:

  • Start tab > Split column > by delimiter
  • Obviously choose a comma as delimiter > Choose Advanced and tick by Row instead of Column.
  • Choose no quotes and confirm.
  • Right click the data in PQ > Transform > Trim

That's it. You can close PowerQuery now and save your changes

I would post the M code, but my Excel is in Dutch so no use.




回答2:


If you are not dealing with a massive amount of data, and using Excel 365 or later versions, you can try the following solution.

Suppose your original data is in range A1:A4 including header,

Highlight range B1:B10, go to your formula bar and enter the following formula and confirm it by pressing Ctrl+Shift+Enter on your keyboard:

=FILTERXML("<a><b>"&TEXTJOIN("</b><b>",,SUBSTITUTE(A1:A4,", ","</b><b>"))&"</b></a>","//b")

If you do not want to show the #N/A error, you can use the IFERROR formula in the following way:

=IFERROR(formula,"")

For the logic behind the use of FILTERXML function, you can give a read to this article: Extract word by position using FILTERXML()

The problem with the above solution is that you need to find out what is a reasonable output range for you to enter the array formula so all output can be displayed.


If you have joined the "mysterious" insider program of Excel, you may be able to simply use the UNIQUE function in the following way to get the list (please note the following is only a guess as I am not in the program so cannot test it out).

Highlight cell B1, enter the following formula, hit Enter key as normal.

=UNIQUE(formula)

And the list will be spilled automatically in range B1:B6.

A problem with this formula is that it will only display duplicated values once. Use it with caution.

An alternative is to use SORT function which will also generate a list automatically including duplicated values but they will not be in the same order as the original list if the original list is in random order.



来源:https://stackoverflow.com/questions/58638875/how-to-use-vlookup-to-split-multiple-valued-cell-into-separate-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!