您能否将一列数据移动到单个单元格中,并用逗号分隔该列中的值?一种反向文本到列。
例如,
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)
到1,2,3,4,5单个单元格中。
使用用户定义的函数比逐个单元地硬编码要灵活得多
使用您的新公式,就像 D6 单元格快照中的公式一样
=ConCat(A1:A5)
您可以使用更复杂的公式,例如 D7
=ConCat(A1:A5,A7:A24)
或 D8 中的公式,即 2D
=concat(A1:B5,A7:A24)

Function ConCat(ParamArray rng1()) As String
Dim X
Dim strOut As String
Dim strDelim As String
Dim rng As Range
Dim lngRow As Long
Dim lngCol As Long
Dim lngCnt As Long
strDelim = ", "
For lngCnt = LBound(rng1) To UBound(rng1)
If TypeOf rng1(lngCnt) Is Range Then
If rng1(lngCnt).Cells.Count > 1 Then
X = rng1(lngCnt).Value2
For lngRow = 1 To UBound(X, 1)
For lngCol = 1 To UBound(X, 2)
strOut = strOut & (strDelim & X(lngRow, lngCol))
Next
Next
Else
strOut = strOut & (strDelim & rng2.Value)
End If
End If
Next
ConCat = Right$(strOut, Len(strOut) - Len(strDelim))
End Function
Run Code Online (Sandbox Code Playgroud)
小智 5
首先,做
=concatenate(A1,",")
Run Code Online (Sandbox Code Playgroud)
在您有值的旁边的下一列中。
其次,复制整个列并转到另一个工作表执行选择性粘贴-> 转置。
您可以使用连接函数并在单元格和字符串之间交替",":
=CONCATENATE(A1,",",A2,",",A3,",",A4,",",A5)
Run Code Online (Sandbox Code Playgroud)