SelectedCells[notebook]
returns a list of CellObject expressions corresponding to the currently selected cells in notebook.
returns the currently selected cells in the notebook in which this function is being evaluated.
SelectedCells
SelectedCells[notebook]
returns a list of CellObject expressions corresponding to the currently selected cells in notebook.
returns the currently selected cells in the notebook in which this function is being evaluated.
Details and Options
- If no cells are selected, SelectedCells returns an empty list.
- If the selection is inside of a cell, SelectedCells returns the cell containing the selection.
- SelectedCells[notebook] is equivalent to Cells[NotebookSelection[notebook]].
- If the selection is inside of an inline cell, then SelectedCells will return the CellObject corresponding to the inline cell. The setting AllowInlineCells->False may be given to cause it to return the top-level cell that contains the selected inline cell.
Examples
open all close allBasic Examples (3)
SelectionMove[EvaluationNotebook[], All, EvaluationCell];
SelectedCells[]Return an empty list if no cell is selected:
SelectedCells[]Return selected cells of a given notebook:
nb = CreateDocument[{TextCell["first", "Title"], TextCell["second", "Section"], ExpressionCell["third", "Input"]}];
SelectionMove[nb, All, Notebook];
SelectedCells[nb]Options (1)
AllowInlineCells (1)
By default, SelectedCells returns selected inline cells, such as this one with the style "Output2":
CellPrint[ExpressionCell[Row[{123, ExpressionCell[456, "Output2"]}], "Output"]]
SelectionMove[EvaluationCell[], After, Cell];
NotebookFind[EvaluationNotebook[], 456, Next];
SelectedCells[]AllowInlineCells->False causes the outermost CellObject to be returned instead:
CellPrint[ExpressionCell[Row[{123, ExpressionCell[456, "Output2"]}], "Output"]]
SelectionMove[EvaluationCell[], After, Cell];
NotebookFind[EvaluationNotebook[], 456, Next];
SelectedCells[AllowInlineCells -> False]Related Guides
History
Text
Wolfram Research (2014), SelectedCells, Wolfram Language function, https://reference.wolfram.com/language/ref/SelectedCells.html.
CMS
Wolfram Language. 2014. "SelectedCells." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SelectedCells.html.
APA
Wolfram Language. (2014). SelectedCells. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SelectedCells.html
BibTeX
@misc{reference.wolfram_2026_selectedcells, author="Wolfram Research", title="{SelectedCells}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/SelectedCells.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_selectedcells, organization={Wolfram Research}, title={SelectedCells}, year={2014}, url={https://reference.wolfram.com/language/ref/SelectedCells.html}, note=[Accessed: 13-June-2026]}