基于重复值连接单元格值?

基本上我的数据(项目编号和它的相关维度)是这样的两列:

FOX6215A - Twin Dimensions (W x D x H): 38.6" x 1.3" x 59.8" FOX6215A - Full Dimensions (W x D x H): 53.6" x 1.3" x 59.8" FOX6215A - Queen Dimensions (W x D x H): 60.6" x 1.3" x 59.8" FOX6215A - King Dimensions (W x D x H): 76.6" x 1.3" x 59.8" FOX6215B - Twin Dimensions (W x D x H): 38.6" x 1.3" x 59.8" FOX6215B - Full Dimensions (W x D x H): 53.6" x 1.3" x 59.8" FOX6215B - Queen Dimensions (W x D x H): 60.6" x 1.3" x 59.8" FOX6215B - King Dimensions (W x D x H): 76.6" x 1.3" x 59.8" FOX6215C - Twin Dimensions (W x D x H): 38.6" x 1.3" x 59.8" FOX6215C - Full Dimensions (W x D x H): 53.6" x 1.3" x 59.8" 

如果列A有重复值,我需要连接列B中的维度(用分隔每个大小的换行符)。 所以期望的结果是:

 FOX6215A - Twin Dimensions (W x D x H): 38.6" x 1.3" x 59.8" - Full Dimensions (W x D x H): 53.6" x 1.3" x 59.8" - Queen Dimensions (W x D x H): 60.6" x 1.3" x 59.8" ... 

由于FOX6215A有多种尺寸。 我完全被困在如何做到这一点。 有任何想法吗?

如果您使用TEXTJOIN()具有Office 365 Excel:

获取项目编号的唯一列表,然后使用此数组公式:

 =TEXTJOIN(CHAR(10),TRUE,IF($A$1:$A$10=D1,$B$1:$B$10,"")) 

作为一个数组公式,在退出编辑模式时,需要使用Ctrl-Shift-Enter而不是Enter来确认。 如果正确完成,则Excel将在公式周围放置{}

请记住在输出单元上启用Wrap Text并相应地resize。

在这里输入图像说明


如果您没有Office 365 Excel:

将此代码放在附加到工作簿的模块中,并使用上述公式:

 Function TEXTJOIN(delim As String, skipblank As Boolean, arr) Dim d As Long Dim c As Long Dim arr2() Dim t As Long, y As Long t = -1 y = -1 If TypeName(arr) = "Range" Then arr2 = arr.Value Else arr2 = arr End If On Error Resume Next t = UBound(arr2, 2) y = UBound(arr2, 1) On Error GoTo 0 If t >= 0 And y >= 0 Then For c = LBound(arr2, 1) To UBound(arr2, 1) For d = LBound(arr2, 1) To UBound(arr2, 2) If arr2(c, d) <> "" Or Not skipblank Then TEXTJOIN = TEXTJOIN & arr2(c, d) & delim End If Next d Next c Else For c = LBound(arr2) To UBound(arr2) If arr2(c) <> "" Or Not skipblank Then TEXTJOIN = TEXTJOIN & arr2(c) & delim End If Next c End If TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim)) End Function