Excel 整列的连接函数

Excel concatenate fuction for whole column

我需要一个解决方案:

A     B
1.    1,2,3,4,5,,,
2.
3.
4.
5.

所以我想像这样连接 A 列:

(A2;",";A3;",";A4;",";A5;",";A6;",";A7;","; and so on)

如果列数较少,我想删除数字后面的逗号 (,) - 例如 5,我连接 7。

我该怎么做?

按照你说的使用函数CONCATENATE。您也可以用鼠标重复连接所有行。

=CONCATENATE(A2, ", ", A3) or =A2 & ", " & A3

有关更多信息,请查看此网站:

Concatenate cells with a space, comma and other characters

可能有更好的方法,但我还是会分享我的 "dumb" 方法。

在B1我会做到= A1 在 B2 =SUBSTITUTE(B1&","&A2,".","") 我只需要将该列填写到最后一行

您可以在 B 列最后一行获得最终结果 这是为了防止重复选择整个列表中的所有单元格(使用连接)

我想,我找到了最简单和最好的解决方案,它是 vba 代码:

Function CONCATENATEMULTIPLE(Ref As Range, Separator As String) As String
Dim Cell As Range
Dim Result As String
For Each Cell In Ref
Result = Result & Cell.Value & Separator
Next Cell
CONCATENATEMULTIPLE = Left(Result, Len(Result) - 1)
End Function

函数:=CONCATENATE MULTIPLE(RANGE; ",")

CONCATENATE Excel Ranges (Using VBA)