excel 宏学习(合并相同内容单元格)

来源:互联网 发布:携程亲子园虐童 知乎 编辑:程序博客网 时间:2024/06/06 06:58
Sub hb()
Dim en&, i&, n&
en = [A1048576].End(3).Row
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Do While i <= en
    i = i + 1
    For n = i + 1 To en
        If Cells(i, 1) <> Cells(n, 1) Or n = en Then
            n = IIf(n = en, en, n - 1)
            Range(Cells(i, 1), Cells(n, 1)).Merge
            i = n
            Exit For
        End If
    Next
Loop
Columns("a").VerticalAlignment = xlCenter
End Sub