excel中能否实现如图所示功能,把前面数据合并到一个单元格中。

2024-11-06 16:44:19
推荐回答(4个)
回答1:

VBA宏,对准工作表标签击右键,选择“查看代码”,粘贴下面代码,关闭VBA后。按ALT+F8,执行宏MyMerge
Sub MyMerge()
Dim R_Output As Range, R_Name As Range, S1 As String, S2 As String, isLast As Boolean
Set R_Output = Range("E2")
S1 = "": S2 = ""
Set R_Name = Range("A2")
isLast = False
Do
isLast = (R_Name.Value = "") And (R_Name.Offset(0, 1).Value = "")
If R_Name.Value <> "" Or isLast Then
If S1 <> "" And S2 <> "" Then
R_Output.Value = S1
R_Output.Offset(0, 1).Value = S2
Set R_Output = R_Output.Offset(1, 0)
End If
S1 = R_Name.Value
S2 = R_Name.Offset(0, 1).Text + " " + R_Name.Offset(0, 2).Text
Else
S2 = S2 + Chr(10) + R_Name.Offset(0, 1).Text + " " + R_Name.Offset(0, 2).Text
End If
Set R_Name = R_Name.Offset(1, 0)
Loop While Not isLast
End Sub

回答2:

用英文模式下的&键进行合并

回答3:

可以实现

回答4:

F1=A1&B1&C1&D1&E1