I think I am lost on some basic issue ...

I created two CellTags, tagone and tagtwo

If I create this palette inputting the following code by hand I get a beautifully working palette that makes me jump to these cells.

    Button["tagone", NotebookFind[InputNotebook[], "tagone", All, CellTags]], 
    Button["tagtwo", NotebookFind[InputNotebook[], "tagtwo", All, CellTags]]}]

If I do put this in a function like the following the palette gets created with right names shown in the buttons, but pressing the buttons nothing happens ... Apparently there is a problem in this code with the use of the counter variable in the For. In this examples it is called celln and in the error monitor I get

Part specification celln$53002 is neither a machine-sized integer nor a list of machine-sized integers.

I though the variables was fixed in the loop ... I am quite puzzled, any guess? Did I just made a rookie mistake? I think this functions was previously working when I originally developed it in December. Maybe my memory is failing.

 Module[{nb, res, list, origlist, celln},
   nb = InputNotebook[];
   origlist = NotebookTools`NotebookCellTags[nb];
   res = {};
   For[celln = 1, celln <= Length[origlist], celln++,
        NotebookFind[nb, origlist[[celln]], All, CellTags, AutoScroll -> True]]];
  • $\begingroup$ I keep trying variations and it seems like the variable nb and the one for the name of the tag are messed up ... $\endgroup$
    – Rho Phi
    Feb 11, 2014 at 3:17

1 Answer 1


I'm always suspicious of code using For, so I rewrote your code in a more functional way. It seems to wrong fine.

Module[{tags, buttons},
  tags = NotebookTools`NotebookCellTags[InputNotebook[]];
  buttons = 
    Button[#, NotebookFind[InputNotebook[], #, All, CellTags, AutoScroll -> True]] & /@ tags;

I had two cells in my test notebook with tags: tag-1 and tag-2. The palette created looks this:


Clicking on one of the buttons scrolls to the indicated cell and selects it.

  • $\begingroup$ You are right, For is an enemy ... I have done essentially the same rewrite using Map as you did too. So pissed by For ... $\endgroup$
    – Rho Phi
    Feb 11, 2014 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.