title: Error 1004 when trying to add a pagebreak from macro
body: <p>I have a spreadsheet that we create using POI, but POI causes some issue whenever I try to set a page break using it. So we've just resorted to setting a specific string in the first column of each row that we want a page break and resorting to a macro to replace that string with a page break. However, whenever I run it I get the error:</p>
  
  <pre><code>Run-time error '1004': unable to set the PageBreak property of the Range class
  </code></pre>
  
  <p>The macro we're using is:</p>
  
  <pre><code>Sub testPrintBreak()
  Application.ScreenUpdating = False
      For i = 2 To ActiveSheet.UsedRange.Rows.Count
          If Cells(i, 1).Value = "EMY-REPLACE WITH PAGE BREAK-EMY" Then
              Cells(i, 1).PageBreak = xlPageBreakManual
          End If
      Next
  Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>We also tried another one:</p>
  
  <pre><code>Sub InsertPageBreaksByKeyphrase()
      Dim rangeSelection As Range
      Dim cellCurrent As Range
  
      Set rangeSelection = Application.Selection
      ActiveSheet.ResetAllPageBreaks
  
      For Each cellCurrent In rangeSelection
          If cellCurrent.Value = "EMY-REPLACE WITH PAGE BREAK-EMY" Then
              ActiveSheet.Rows(cellCurrent.Row + 1).PageBreak = _
                  xlPageBreakManual
          End If
      Next cellCurrent
  End Sub
  </code></pre>
  
  <p>Which gave the same error.</p>