Excel“UnCONCATENATE”/在函数中爆炸/将单元格转换为数组 [英] Excel "UnCONCATENATE"/explode in function / Convert cell into array

查看:186
本文介绍了Excel“UnCONCATENATE”/在函数中爆炸/将单元格转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Excel 2010Unconcatenate一个字符串。是的,我知道这不是一个真正的字。这么多我有一个单元格不能分割成多个列,单元格如下所示:



项目1,项目2,项目3



现在这个单元格可能有0-?项目。我想将一个单元格与另一个单页格中的列进行比较。我相信我需要使用匹配函数来执行此操作,但是我需要将第一个单元格转换为一个函数中的数组,并使用分隔符作为逗号。
到目前为止,我有= MATCH( 单元格 中的每个项目,SHEET2!A:A,0)



任何帮助都会很好。我知道=左和=对,但我不认为这些将工作,因为每个单元格中的项目数可能不一样。谢谢



编辑:



详细说明:
在我的第一张表中我有一个下拉框。当您选择项目时,它会在该项目的表格2上执行vlookup。当这种情况发生时,我希望它也检查该行(项目1,项目2,项目3)中的单元格E是否匹配表3中列中的任何单个单元格

解决方案

以下代码暴露了VBA的Split函数,用于工作表使用 - 它返回使用指定的分隔符分割的项目的行数组。例如,如果单元格A1包含文本项目1,项目2),则EXPLODE(A1,,)将返回具有元素项目1和项目2的数组。

 函数EXPLODE(str As String,可选分隔符作为Variant)As Variant 
如果IsMissing(delimiter)然后
delimiter =
结束如果
EXPLODE =拆分(str,分隔符)
结束函数

它是一个数组函数。要在电子表格中使用返回的元素,请执行以下操作:




  • 选择要在其中显示爆炸项目的单元格

  • 输入使用源字符串(或包含源的单元格的引用)和分割完成的分隔符来指定单元格的功能

  • 完成条目使用控件 - Shift - 输入组合键。



或者,可以使用INDEX函数选择单个元素 - = INDEX(EXPLODE(A1,1,2)将返回项2 (给定一个范围或数组,INDEX函数返回第i行和第j列的值。)此用法不需要​​将公式作为数组公式输入。



对于您的用例,与其他功能的组合将是有序的。您有一个字符串,其中包含多个aa,bb,cc形式的项目(VLOOKUP的结果),并且要确定这个字符串的任何元素可以作为列A中的任何单元格中的单独项目找到。如果找到所有元素,您需要一个返回True的函数,否则返回False。以下公式实现了这一结果:

  = SUM(SIGN(IFERROR(MATCH(TRIM(EXPLODE(D1, ),$ A:$ A,0),0)))= COUNTA(EXPLODE(D1,,))

它是一个数组公式,需要输入控件 - Shift - 输入。请注意,我使用单元格D1的内容来代替查找值。 TRIM功能将多个项目的字符串元素之间的任何空格区分开。


I am trying to "Unconcatenate" a string in Excel 2010. Yes, I know that is not a real word. So pretty much; I have a cell that can not be split into multiple columns the cell looks like this:

Item 1, Item 2, Item 3

Now this cell may have 0-? items. I am wanting to compare that one cell against a column in another sheet. I believe I would need to use the match function to do this, but I need that first cell to be converted into an array in a function with the delimiter as the comma. So far I have =MATCH(Each item in cell, SHEET2!A:A, 0)

Any help would be nice. I am aware of =Left and =Right, but I do not think these will work because the number of items in each cell may not be the same. Thanks

Edit:

Detailed discription: In my first sheet I have a dropdown box. When you choose items it does a vlookup on sheet 2 on this item. When this happens I want it to also check if cell E in that row (item 1, item 2, item 3) match any of the individual cells in a column in sheet 3

解决方案

The following code exposes VBA's Split function for worksheet use--it returns a row array of items that have been split using a specified delimiter. For example, if cell A1 contained the text "Item 1,Item 2"), EXPLODE(A1,",") would return an array with elements "Item 1" and "Item 2".

  Function EXPLODE(str As String, Optional delimiter As Variant) As Variant
      If IsMissing(delimiter) Then
          delimiter = " "
      End If
      EXPLODE = Split(str, delimiter)
  End Function 

It is an array function. To use the returned elements in the spreadsheet:

  • Select the cells in which you want the "exploded" items show
  • Enter the function specifying the cell with the source string (or reference to the cell which contains the source) and the delimiter on which the split will be done
  • Complete the entry using the Control-Shift-Enter key combination.

Alternatively, individual elements can be chosen using the INDEX function--=INDEX(EXPLODE(A1,1,2) would return "Item 2" using the previous example. (Given a range or array, the INDEX function returns the value in the ith row and jth column.) This usage does not require the formula to be entered as an array formula.

For your use case, a combination with other functions would be in order. You have a string with multiple items of the form "aa, bb, cc" (the result of a VLOOKUP) and want to determine whether any of the elements of this string can be found as individual items in any of the cells in column A. You want a function that will return True if all of the elements are found, and False otherwise. The following formula achieves that result:

  =SUM(SIGN(IFERROR(MATCH(TRIM(EXPLODE(D1,",")),$A:$A,0),0)))=COUNTA(EXPLODE(D1,","))

It is an array formula and needs to be entered with Control-Shift-Enter. Note that I used the contents of cell D1 in lieu of your lookup value. The TRIM function strips out any extraneous spaces between the elements of the string with multiple items.

这篇关于Excel“UnCONCATENATE”/在函数中爆炸/将单元格转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆