Cells

Cells[]
returns a list of CellObject expressions corresponding to cells in the current notebook.

Cells[obj]
returns the list of CellObject expressions in obj.

Cells[NotebookSelection[notebook]]
returns the list of CellObject expressions for currently selected cells.

Details and OptionsDetails and Options

  • Cells always returns a list if the value of obj is valid. Otherwise, it returns $Failed.
  • obj may be a NotebookObject or a CellObject. If obj is a CellObject, then Cells returns the inline cells in the specified cell.
  • Cells can further refine the list of returned CellObject expressions by specifying one or more of the following options.
  • CellIDcell IDs to match
    CellLabelIn/Out label strings to match
    CellStylenamed cell styles to match
    CellTagscell tags to match
    Evaluatorcells that match the specified evaluator
    GeneratedCellmatch only generated output cells if True, or only non-generated cells if False
  • When multiple options are passed to Cells, the return result will only include CellObject expressions matching cells that meet all conditions.
  • If a list of values is given to any single option of Cells, then it will match any of the given values.
  • If the selection in a notebook is inside of a cell, then Cells[NotebookSelection[notebook]] returns the cell containing the selection.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Return a range of cells in the evaluation notebook:

In[1]:=
Click for copyable input
Out[1]=

Return all of the cells in the specified notebook:

In[1]:=
Click for copyable input
Out[1]=

Return the first three Input cells in the evaluation notebook:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2012
(9.0)
| Updated in 2014
(10.0)