列A | 列B | 列C |
---|---|---|
a | 1 | 1 |
a | 2 | 2 |
a | 3 | 3 |
a | 4 | 4 |
b | 1 | 1 |
b | 2 | 2 |
c | 1 | 1 |
c | 2 | 2 |
c | 3 | 3 |
c | 4 | 4 |
d | 1 | 1 |
e | 1 | 1 |
e | 2 | 2 |
f | 1 | 1 |
... | ... | ... |
如上表格,如何在列A的每一个区分中间插入分页符,例如在a,b中间插入分页符,在b,c中间插入分页符?
Sub 不同行值分隔页()
Application.ScreenUpdating = False
endrow = [A65536].End(3).Row
For i = endrow To 2 Step -1
If Range("A" & i).Value <> Range("A" & i + 1).Value Then
Range("A" & i + 1).Select
Range("A" & i + 1).Activate
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
Next
Application.ScreenUpdating = True
End Sub