Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]]];
share|improve this question
I keep trying variations and it seems like the variable nb and the one for the name of the tag are messed up ... – Roberto Franceschini Feb 11 '14 at 3:17

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.

share|improve this answer
You are right, For is an enemy ... I have done essentially the same rewrite using Map as you did too. So pissed by For ... – Roberto Franceschini Feb 11 '14 at 4:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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