SilentRomance
New Member
- Joined
- Aug 4, 2021
- Messages
- 46
- Office Version
- 2016
- 2010
- Platform
- Windows
This is what I want to do.
I want to locate Page break with in a month and count them.
Assume that there are 5 PB in month of January, 7 in Feb and 10 in March so there are 22 PB.
This is what I did
What I expected count of Page Break is 7 in that month (Feb) but it gives me all the total of PB (22).
Is there better way to code this guys?
I want to locate Page break with in a month and count them.
Assume that there are 5 PB in month of January, 7 in Feb and 10 in March so there are 22 PB.
This is what I did
VBA Code:
For r = LastRow To StartRow + 1 Step -1
If Month(Cells(r, "A")) <> Month(Cells(r - 1, "A")) Then
'========================================================
mn = Month(Cells(r, "A"))
If mn = 2 Then '#February
pbCnt = ws.HPageBreaks.Count
pbLoc = 0
pRprev = 0
If pbC >= 1 Then
For Each pb In ws.HPageBreaks
pbLov = pb.Location.Row
If pRprev = 0 Then
sumToRow = 1
Else
sumToRow = pRprev
End If
Cells(str, 2).Value = "Total"
pRprev = pb.Location.Row
Next pb
End If
End If
What I expected count of Page Break is 7 in that month (Feb) but it gives me all the total of PB (22).
Is there better way to code this guys?