Refer to pagebreak by the row number

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
As far as I'm aware, horizontal pagebreaks are referred to by its number, such as

Code:
    Sheet1.HPageBreaks(1).Delete

I want to refer to its row number but the following code fails:

Code:
Dim i As Long

For i= 1 To 100
            
     If Sheet1.Rows(Ticker).PageBreak <> xlPageBreakNone Then
                    
         If (i- 25) Mod Increment <> 0 Then
                    
             Sheet1.HPageBreaks(Sheet1.rows(i)).Delete
                    
          End If
                    
        End If
                
Next Ticker

Error message:

Code:
Run-time error '424'

Object required

on this line:

Code:
Sheet1.HPageBreaks(Sheet1.rows(i)).Delete

Is it possible to refer to horizontal page breaks by its row number?

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
As far as I'm aware, horizontal pagebreaks are referred to by its number, such as

Code:
    Sheet1.HPageBreaks(1).Delete

I want to refer to its row number but the following code fails:

Code:
Dim i As Long

For i= 1 To 100
           
     If Sheet1.Rows(Ticker).PageBreak <> xlPageBreakNone Then
                   
         If (i- 25) Mod Increment <> 0 Then
                   
             Sheet1.HPageBreaks(Sheet1.rows(i)).Delete
                   
          End If
                   
        End If
               
Next Ticker

Error message:

Code:
Run-time error '424'

Object required

on this line:

Code:
Sheet1.HPageBreaks(Sheet1.rows(i)).Delete

Is it possible to refer to horizontal page breaks by its row number?

Thanks
EDIT SORTED:

Code:
Dim a As Long

a = 0

Dim i As Long

For i= 1 To 100
           
     If Sheet1.Rows(Ticker).PageBreak <> xlPageBreakNone Then

         a = a + 1
                   
         If (i- 25) Mod Increment <> 0 Then
                   
             Sheet1.HPageBreaks(a).Delete
                   
          End If
                   
        End If
               
Next Ticker
 
Upvote 0

Forum statistics

Threads
1,214,896
Messages
6,122,132
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top