示例

Sub cc()
Application.DisplayAlerts = False
Set a = ActiveSheet
Set xuan = Application.InputBox("选择合并的列", Type:=8)
lie = xuan.Column
Set Rng = UsedRange.CurrentRegion
Rng.Select
Rng.Sort Key1:=a.Cells(1, lie), Order1:=1, Header:=1
x = Rng.Rows.Count
For i = 2 To x
For j = i + 1 To x + 1
If a.Cells(i, lie) <> a.Cells(j, lie) Then
Range(a.Cells(i, lie), a.Cells(j - 1, lie)).Merge
i = j - 1
Exit For
End If
Next
Next
Application.DisplayAlerts = True
End Sub
整体思路
主要目标是合并工作表中选定列中相邻的具有相同值的单元格,以改善数据的可读性。
- 获取当前活动工作表并选择要操作的列。

1万+

被折叠的 条评论
为什么被折叠?



