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