SELECTION macro

Returns the reference or object identifier of the selection as an external reference. Use SELECTION to return information about the current selection for use in other macro formulas.

Syntax

SELECTION( )

If a cell or range of cells is selected, Microsoft Excel returns the corresponding external reference. If an object is selected, Microsoft Excel returns the object identifier listed in the following table.

Item selected

Identifier returned

Imported graphic

Picture n

Linked graphic

Picture n

Chart picture

Picture n

Linked chart

Chart n

Range

Picture n

Linked range

Picture n

Text box

Text n

Button

Button n

Rectangle

Rectangle n

Oval

Oval n

Line

Line n

Arc

Arc n

Group

Group n

Freehand drawing or polygon

Drawing n

SELECTION also returns the identifiers of chart items. The identifiers returned are the same as the identifiers you specify when you use the SELECT function. For a list of these identifiers, see the description of item_text in SELECT.

If you select cells and use the value returned by SELECTION in a function or operation, you usually get the value contained in the selection instead of its reference. References are automatically converted to the contents of the reference. If you want to work with the actual reference, use SET.NAME to assign a name to it, even if the reference refers to objects. See the last example following. You can also use the REFTEXT function to convert the reference to text, which you can then store or manipulate.

Remarks

 

Examples

If the sheet in the active window is named SHEET1 in the workbook BOOK1, and if A1:A3 is the selection, then:

SELECTION() equals [BOOK1]SHEET1!A1:A3

The following macro formula moves the current selection one row down:

SELECT(OFFSET(SELECTION(), 1, 0))

The above formula is particularly useful for moving incrementally through a database to add or modify records.

The following macro formula defines the name "EntryRange" on the active sheet to refer to one row below the current selection on the active sheet:

DEFINE.NAME("EntryRange", OFFSET(SELECTION(), 1, 0))

The following macro formula defines the name "Objects" on your macro sheet to refer to the object names in the current multiple selection:

SET.NAME("Objects", SELECTION())

Related Functions

ACTIVE.CELL   Returns the reference of the active cell

SELECT   Selects a cell, graphic object, or chart

Return to index