按照B列 是否一致 填充相同序号,并按照序号一致 合并单元格Sub wp()
Application.DisplayAlerts = False '禁止提示信息的显示,合并单元格会有是否保留左上角的提示
Range("a2") = Range("a2").Row - 1
Range("a3:a92").Select
s = Selection.Rows.Count
For i = 3 To s + 2 '按B列是否一致 填充序号
If Range("b" & i) <> Range("b" & i - 1) Then
Range("a" & i) = Range("a" & i - 1) + 1
Else
Range("a" & i) = Range("a" & i - 1)
End If
Next
'''以下按照上面填充的序号 进行相同序号合并单元格
k = 2
For i = 3 To s + 2
If Range("a" & i) <> Range("a" & k) Then
Range("a" & k & ":" & "a" & i - 1).Select
Selection.Merge
k = i
End If
Next
End Sub
|