# Controlling page breaks

I'm writing a bunch of cells to a new notebook nb and am trying to control the pagebreaks. That is, I want a pagebreak after each Length[listOef] number of cells. But sometimes, I get two pagebreaks, depending on which random permutatation of listOef.

listOef


contains "aantalVragen" number of cells given by the user.

Then I use the following code:

nb = CreateDocument[Null, Magnification -> 1.5, ShowCellTags -> False,
PageHeaders -> {{None, None, None}, {None, None, None}},
ShowCellLabel -> True];

(*Initialize exported notebook*)
SelectionMove[nb, Next, Cell];
NotebookDelete[nb];

allPermutations = Table[RandomPermutation[aantalVragen], {aantalToetsen}];

Do[
NotebookWrite[nb, Cell["Toets 1." <> ToString[toetsNummer], "Title",
PageBreakAbove -> True]];
NotebookWrite[nb, Cell[datumToets, "Text"]];
NotebookWrite[nb, Cell["Wiskunde", "Text", TextAlignment -> Right]];
NotebookWrite[nb, Cell["G. Hollander", "Text", TextAlignment -> Right]];

(* Test toetsNummer *)
Do[
NotebookWrite[nb, Permute[listOef, allPermutations[[toetsNummer]]][[vraagNummer]]];
SelectionMove[nb, Previous, Cell];
SetOptions[NotebookSelection[nb],
CellLabel -> "Vraag " <> ToString[vraagNummer] <> "."];
SelectionMove[nb, After, Notebook])
,
{vraagNummer, aantalVragen}];

**SelectionMove[nb, Previous, Cell];
SetOptions[NotebookSelection[nb], PageBreakBelow -> False];
SelectionMove[nb, Next, Cell];**
,
{toetsNummer, aantalToetsen}]



Why does I sometimes get two pagebreaks? I then check if the last cell of the page has a pagebreak with the code

SelectionMove[nb,Previous,Cell];
Options[NotebookSelection[nb]]


at the end of every inner Do[] (which is for every page), but I get an empy list of options, so I don't know if there is a pagebreak or not.

Also, I'm not quite sure of the part of the code in ** Bold **: I'm trying to suppress pagebreaks at the end of a page, as I'm doing that with

 NotebookWrite[nb,
Cell["Toets 1." <> ToString[toetsNummer], "Title", PageBreakAbove -> True]];


at the beginning of the code. But that doesn't seem to prevent double page breaks, sometimes.