按Alt+F11,打开VBA编辑器,插入一个模块,把下面的代码贴进去,按F5执行
Sub 宏1()
lastrow = Cells(Rows.Count, 2).End(3).Row
i = 1
k = 1
Do While i <= lastrow
If Left(Cells(i, 2), 6) = Left(Cells(i + 1, 2), 6) Then
i = i + 1
Else
Range(Cells(k, 1), Cells(i, 1)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
i = i + 1
k = i
End If
Loop
End Sub
测试通过。