ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Counting Manual Page Breaks Only (https://www.excelbanter.com/excel-programming/438854-counting-manual-page-breaks-only.html)

Kevin R

Counting Manual Page Breaks Only
 
I have a very long spreadsheet where I've used vba to reset all page breaks
and then manually insert page breaks before key cells. I'm trying now to
count the number of manual page breaks using ActiveSheet.HPageBreaks.Count
but it appears to be counting both the manual and automatic (those reinserted
by excell between the manual breaks). Is there a way around this??

Rick Rothstein

Counting Manual Page Breaks Only
 
This function should return the value you want...

Function NumberOfManualPageBreaks(Optional WS As Worksheet) As Long
Dim HP As HPageBreak
If WS Is Nothing Then Set WS = ActiveSheet
For Each HP In WS.HPageBreaks
If HP.Type = xlPageBreakManual Then
NumberOfManualPageBreaks = NumberOfManualPageBreaks + 1
End If
Next
End Function

Simply pass it a reference to the worksheet whose manual horizontal page
breaks you want to count or omit the argument completely to return the
manual horizontal page break count for the active sheet.

--
Rick (MVP - Excel)


"Kevin R" wrote in message
...
I have a very long spreadsheet where I've used vba to reset all page breaks
and then manually insert page breaks before key cells. I'm trying now to
count the number of manual page breaks using ActiveSheet.HPageBreaks.Count
but it appears to be counting both the manual and automatic (those
reinserted
by excell between the manual breaks). Is there a way around this??




All times are GMT +1. The time now is 01:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com