首页 > 其他分享 >VBA合并相同单元格

VBA合并相同单元格

时间:2023-02-07 18:01:50浏览次数:40  
标签:Dim VBA End Sub Cells 单元格 合并 Integer

 

vba即使在2023年,依然强大和效率极高。

Sub 合并()
        Call 合并1
        Call 合并2
        Call 合并3
        Call 合并4
End Sub


Sub 合并1()
        Dim j As Integer
        Dim i As Integer

        Application.DisplayAlerts = False
        j = [A65536].End(xlUp).Row
        For i = j To 2 Step -1
                If Cells(i, 1) = Cells(i - 1, 1) Then
                        Range(Cells(i - 1, 1), Cells(i, 1)).Merge
                End If
        Next
End Sub

Sub 合并2()
        Dim j As Integer
        Dim i As Integer

        Application.DisplayAlerts = False
        j = [A65536].End(xlUp).Row
        For i = j To 2 Step -1
                If Cells(i, 2) = Cells(i - 1, 2) Then
                        Range(Cells(i - 1, 2), Cells(i, 2)).Merge
                End If
        Next
End Sub

 

Sub 合并3()
        Dim j As Integer
        Dim i As Integer

        Application.DisplayAlerts = False
        j = [A65536].End(xlUp).Row
        For i = j To 2 Step -1
                If Cells(i, 3) = Cells(i - 1, 3) Then
                        Range(Cells(i - 1, 3), Cells(i, 3)).Merge
                End If
        Next
End Sub

 

Sub 合并4()
        Dim j As Integer
        Dim i As Integer

        Application.DisplayAlerts = False
        j = [A65536].End(xlUp).Row
        For i = j To 2 Step -1
                If Cells(i, 4) = Cells(i - 1, 4) Then
                        Range(Cells(i - 1, 4), Cells(i, 4)).Merge
                End If
        Next
End Sub

标签:Dim,VBA,End,Sub,Cells,单元格,合并,Integer
From: https://www.cnblogs.com/aarond/p/17099347.html

相关文章