({{, (RefLink[SelectionMove, paclet:ref/SelectionMove])[obj,dir,unit]
moves the current selection in an open notebook in the front end in the direction dir by the specified unit. }, {, (RefLink[SelectionMove, paclet:ref/SelectionMove])[obj,dir,unit,n]
repeats the move n times. }})

OpenersNotesSection(Spacer1)Details and Options

The first argument of (RefLink[SelectionMove, paclet:ref/SelectionMove]) can be a (RefLink[NotebookObject, paclet:ref/NotebookObject]), (RefLink[CellObject, paclet:ref/CellObject]), or (RefLink[BoxObject, paclet:ref/BoxObject]).

Possible direction specifications are:

Possible unit specifications are:

Unless the option setting (RefLink[AutoScroll, paclet:ref/AutoScroll])->(RefLink[False, paclet:ref/False]) is given, the front end will scroll a notebook so that the result of (RefLink[SelectionMove, paclet:ref/SelectionMove]) is visible. »

The front end will also usually highlight the region corresponding to the result.

With direction specifications (RefLink[After, paclet:ref/After]) and (RefLink[Before, paclet:ref/Before]), (RefLink[SelectionMove, paclet:ref/SelectionMove]) will usually make the current selection be an insertion point between two units of the specified type. »

(RefLink[SelectionMove, paclet:ref/SelectionMove]) returns (RefLink[$Failed, paclet:ref/$Failed]) if it cannot move the selection in the way you request.

A (RefLink[GeneratedCell, paclet:ref/GeneratedCell]) corresponds to an element of the output.

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Select the first cell after the initial selection position:

nb=NotebookPut[Notebook[{Cell["Subsection heading","Subsection"],Cell["Some text.","Text"]}]];
SelectionMove[nb,Next,Cell]

Select the third cell after the initial selection position:

nb=NotebookPut[Notebook[{Cell["Subsection heading","Subsection"],Cell["Some text.","Text"],Cell["Some more text.","Text"]}]];
SelectionMove[nb,Next,Cell,3]

Move selection to a cell:

obj=EvaluationCell[];
SelectionMove[obj,All,Cell]

Select the button that triggered the evaluation:

Button["click",SelectionMove[EvaluationBox[],All,Expression]]

OpenersExampleSection1(Spacer1)Scope  (1)

Create a notebook:

nb=CreateWindow[DocumentNotebook[{CellGroup[{TextCell["Text Group","Section"],TextCell["Mary had a little lamb.","Text"],TextCell["Its fleece was white as snow.","Text"]}],CellGroup[{TextCell["Graphics Group","Section"],ExpressionCell[ Plot[Exp[-x^2],{x,-3,3}],"Output"]}]}]];

Move the selection to the first letter:

SelectionMove[nb,Before,CellContents];
SelectionMove[nb,All,Character]

Move the selection to the (RefLink[CellGroup, paclet:ref/CellGroup]):

SelectionMove[nb,All,CellGroup]

Move the selection to the graphics within the cell:

SelectionMove[nb,Next,CellContents,2]

Move the selection to the end of the notebook:

SelectionMove[nb,After,Notebook]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)AutoScroll  (1)

Normally, any selection is visibly displayed in the notebook window regardless of its location:

nb=NotebookPut[Notebook[{Cell["Subsection heading","Subsection"],Sequence@@Table[Cell["Some text.","Text"],{50}]}]];
SelectionMove[nb,Next,Cell,30]

With (RefLink[AutoScroll, paclet:ref/AutoScroll]) set to (RefLink[False, paclet:ref/False]), the selection is offscreen:

nb=NotebookPut[Notebook[{Cell["Subsection heading","Subsection"],Sequence@@Table[Cell["Some text.","Text"],{50}]}]];
SelectionMove[nb,Next,Cell,30,AutoScroll->False]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[SelectionMove, paclet:ref/SelectionMove]) regards inline cells as equivalent to words:

nb=NotebookPut[Notebook[{Cell[TextData[{Cell["Some text","Subsection"]," that begins with an inline subsection cell."}],"Text"]}]];
SelectionMove[nb,Before,CellContents]

SelectionMove[nb,Next,Word]

To emulate keyboard cursor movement, use a front end token such as (StringTypeLink["MoveNext", paclet:ref/frontendobject/MoveNext]):

FrontEndExecute[FrontEndToken[nb,"MoveNext"]]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

(RefLink[SelectionMove, paclet:ref/SelectionMove]) can only select multiple cells as part of a (RefLink[CellGroup, paclet:ref/CellGroup]) unit specification:

nb=NotebookPut[Notebook[{Cell["Subsection heading","Subsection"],Cell["Some text.","Text"],Cell["Some more text.","Text"]}]];
SelectionMove[nb,Next,CellGroup]

To select a series of individual cells, use a front end token such as "SelectNextLine":

nb=NotebookPut[Notebook[{Cell["Subsection heading","Subsection"],Cell["Some text.","Text"],Cell["Some more text.","Text"]}]];
SelectionMove[nb,Next,Cell];
FrontEndExecute[FrontEndToken[nb,"SelectNextLine"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NotebookSelection, paclet:ref/NotebookSelection])  ▪  (RefLink[SelectedCells, paclet:ref/SelectedCells])  ▪  (RefLink[Cells, paclet:ref/Cells])  ▪  (RefLink[NotebookFind, paclet:ref/NotebookFind])  ▪  (RefLink[NotebookWrite, paclet:ref/NotebookWrite])  ▪  (RefLink[NotebookRead, paclet:ref/NotebookRead])  ▪  (RefLink[NextCell, paclet:ref/NextCell])  ▪  (RefLink[PreviousCell, paclet:ref/PreviousCell])  ▪  (RefLink[ParentCell, paclet:ref/ParentCell])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Notebooks from the Kernel, paclet:tutorial/ManipulatingNotebooksFromTheKernel])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Low-Level Notebook Programming, paclet:guide/LowLevelNotebookProgramming])}})}})