就你目前的截图,代码如下:
Sub test()
Dim i, irow As Integer
irow = Range("e65536").End(xlUp).Row
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = irow To 7 Step -1
If Cells(i, 5) <> "" And Cells(i + 1, 5) <> "" And Cells(i, 5) = Cells(i + 1, 5) Then
Range(Cells(i + 1, 5), Cells(i, 5)).Merge
End If
Next
Range(Cells(6, 5), Cells(irow, 5)).HorizontalAlignment = xlCenter
Range(Cells(6, 5), Cells(irow, 5)).VerticalAlignment = xlCenter
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub