答案1
你可以用宏来实现
Sub Flatten_em()
Dim inRow, outRow, outCol As Integer
Dim CheckVal As String
inRow = 3
outRow = 2
Sheets(1).Select
Rows("1:1").Select
Selection.Copy
Sheets(2).Select
Rows("1:1").Select
ActiveSheet.Paste
Sheets(1).Select
CheckVal = Cells(2, 2)
Range(Cells(2, 1), Cells(2, 7)).Select
Selection Copy
Sheets(2).Select
Cells(outRow, 1).Select
ActiveSheet.Paste
Do Until Cells(inRow, 2) = ""
outCol = 8
Do While Cells(inRow, 2) = CheckVal
Sheets(1).Select
Range(Cells(inRow, 4), Cells(inRow, 7)).Select
Sheets(2).Select
Cells(outRow, outCol).Select
ActiveSheet.Paste
outCol = outCol + 4
inRow = inRow + 1
Loop
CheckVal = Sheets(1).Cells(inRow, 2)
outRow = outRow + 1
Loop
End Sub
答案2
使用公式CONCATENATE
例如,要将 A3、B3、C3、D3、E3、F3、G3 合并到合并单元格,请执行以下操作:
在合并单元格中输入以下公式
=CONCATENATE(A3,B3,c3,D3,E3,F3,G3)