如果这些相同的行已经在另一列中合并,我需要帮助查找可以跨特定列中的行合并单元格的宏。下面是我现在所拥有的屏幕截图,其中显示了B列中的单元格需要根据已在A列中合并的单元格进行合并。
以下屏幕截图是宏运行后我需要电子表格的样子
答案 0 :(得分:0)
nixda已经回答了......
Sub mergecolumn()
Dim cnt As Integer
Dim rng As Range
Dim str As String
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
cnt = Cells(i, 1).MergeArea.Count
Set rng = Range(Cells(i, 2), Cells(i - cnt + 1, 2))
For Each cl In rng
If Not IsEmpty(cl) Then str = str + vbNewLine + cl
Next
If str <> "" Then str = Right(str, Len(str) - 2)
Application.DisplayAlerts = False
rng.Merge
rng = str
Application.DisplayAlerts = True
str = ""
i = i - cnt + 1
Next i
End Sub