Sub HPageBreak()
ActiveWindow.View = 2
For i = 1 To ActiveSheet.HPageBreaks.Count
MsgBox ActiveSheet.HPageBreaks(i).Location.Row-1
Next
ActiveWindow.View = 1
End Sub
Sub HPageBreaks_BorderAround()
Dim i As Long, ir As Long
Application.ScreenUpdating = False
With ActiveSheet
ActiveWindow.View = 2
[a1].Resize(.HPageBreaks(1).Location.Row - 1, 7).BorderAround LineStyle:=1
For i = 2 To .HPageBreaks.Count
ir = .HPageBreaks(i).Location.Row - .HPageBreaks(i - 1).Location.Row
Cells(.HPageBreaks(i - 1).Location.Row, 1).Resize(ir, 7).BorderAround LineStyle:=1
Next
ActiveWindow.View = 1
End With
Application.ScreenUpdating = True
End Sub
Bảng tính của em có hơn chục trang mà code này chạy chậm kinh (máy không đến nõi cùi lắm) ACE xem và cải thiện tốc độ giúp em với
Sub HPageBreaks_BorderAround()
Application.ScreenUpdating = False
On Error Resume Next
With ActiveSheet
ActiveWindow.View = 2
For i = 1 To .HPageBreaks.Count
.Cells(.HPageBreaks(i).Location.Row, 1) = "x"
Next
With .[a:a].SpecialCells(2)
For i = 1 To .Areas.Count
Range(.Areas(i), .Areas(i + 1)(0)).Offset(, 1).Resize(, 10).BorderAround 1
Next
.Areas(1)(0, 2).Resize(, 10).Borders(4).LineStyle = 1
.Areas(.Areas.Count)(1, 2).Resize(, 10).Borders(3).LineStyle = 1
End With
.[a:a].Clear
.[b5].SpecialCells(5).BorderAround 1
ActiveWindow.View = 1
End With
End Sub