4

I want to assign each cell in my current notebook a tag so that I can rerun cells with specific tags later in the notebook (Using a method similar to this answer).

My questions are

  • How do I assign cells in my current notebook tags?
  • How do I view the tags that I have assigned?
AzJ
  • 697
  • 4
  • 14

2 Answers2

7

You can use the menu item Cell | CellTags to do this. If you want to inspect and modify CellTags programmatically, you can use CurrentValue and SetOptions. For example:

cell = PreviousCell[];
CurrentValue[cell, CellTags]

{}

Change the tag:

SetOptions[cell, CellTags->"FOO"]

Check:

CurrentValue[cell, CellTags]

"FOO"

Another useful function is Cells, which will return a list of Cell objects satisfying various criteria.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
1

For thoose looking at this question in the future if you want to label the first 3 input cells cell tags use the following

{cell1, cell2, cell3} = Cells[CellStyle -> {"Input"}][[1 ;; 3]]
SetOptions[cell1, CellTags -> {"FOO"}]
SetOptions[cell2, CellTags -> {"FOO2"}]
SetOptions[cell3, CellTags -> {"FOO3"}]
(*Check cell tags*)
CurrentValue[{cell1, cell2, cell3}, CellTags]
AzJ
  • 697
  • 4
  • 14