Excel VBA ScreenUpdate = False Error while finding Page Breaks

While running the code below, if I have Application.ScreenUpdate = False, I receive a runtime error on the Select line:

    Dim groupStartRow As Double
    Dim groupEndRow As Double
    Dim currentPageBreak As Double
    Dim i
    i = 1
    
    If NewWorkbook.Worksheets(NewClientWorksheet).HPageBreaks.Count > 0 Then
    
    With NewWorkbook.Worksheets(NewClientWorksheet)
        
        Do Until i > .HPageBreaks.Count
            
            
           .HPageBreaks(i).Location.EntireRow.Select
            currentPageBreak = Selection.Row
    
            
            If currentPageBreak < .Range("AssetTotal").Row Then
                'Copy table headers
                .Rows("3:5").Copy
                .Rows(currentPageBreak & ":" & currentPageBreak).Insert Shift:=xlDown
    
            End If
            
            groupStartRow = .Range("InvestAndAdmin").Cells.Row
            groupEndRow = .Range("InvestAndAdminEnd").Cells.Row
            
            
            If currentPageBreak > groupStartRow And currentPageBreak <= groupEndRow Then
        
                .Range("InvestAndAdmin").PageBreak = xlPageBreakManual

            End If
            
            groupStartRow = .Range("AddFeesStart").Cells.Row
            groupEndRow = .Range("AddFeesEnd").Cells.Row
            
            
            If currentPageBreak > groupStartRow And currentPageBreak <= groupEndRow Then
        
                .Range("AddFeesStart").PageBreak = xlPageBreakManual

            End If
            
            groupStartRow = .Range("FEE_DETAILS").Cells.Row
            groupEndRow = .Cells(Rows.Count, "B").End(xlUp).Row
 
         
            If currentPageBreak > groupStartRow And currentPageBreak < groupEndRow Then
                If groupStartRow + 1 = currentPageBreak Or groupStartRow + 2 = currentPageBreak Then
                    .Range("FEE_DETAILS").PageBreak = xlPageBreakManual
                
                Else
                    .Rows(groupStartRow & ":" & groupStartRow + 1).Copy
                    .Rows(currentPageBreak & ":" & currentPageBreak).Insert Shift:=xlDown
                End If
            End If
            
            i = i + 1
            
        Loop
            
        
    End With
    End If

Open in new window


If I leave the statement true, the coding works.  Is there any work around other than temporarily allowing screenupdates for this section of coding?

Or is there another way to find the page break location other than using the .Select?
pdkolmoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Avoid Select wherever you can. So instead of

.HPageBreaks(i).Location.EntireRow.Select
            currentPageBreak = Selection.Row

Open in new window


do
currentPageBreak = .HPageBreaks(i).Location.EntireRow.Row

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Did that help?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.