Skip to content

Latest commit

 

History

History
57 lines (36 loc) · 1.68 KB

Excel.Application.PreviousSelections.md

File metadata and controls

57 lines (36 loc) · 1.68 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
Application.PreviousSelections property (Excel)
vbaxl10.chm133191
vbaxl10.chm133191
Excel.Application.PreviousSelections
967ba122-700c-dca5-1b95-aeaf59e9f19c
04/05/2019
medium

Application.PreviousSelections property (Excel)

Returns an array of the last four ranges or names selected. Each element in the array is a Range object. Read-only Variant.

Syntax

expression.PreviousSelections (Index)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
Index Optional Variant The index number (from 1 to 4) of the previous range or name.

Remarks

Each time you go to a range or cell by using the Name box or the Go To command (Edit menu), or each time a macro calls the Goto method, the previous range is added to this array as element number 1, and the other items in the array are moved down.

Example

This example displays the cell addresses of all items in the array of previous selections. If there are no previous selections, the LBound function returns an error. This error is trapped, and a message box appears.

On Error GoTo noSelections 
For i = LBound(Application.PreviousSelections) To _ 
 UBound(Application.PreviousSelections) 
 MsgBox Application.PreviousSelections(i).Address 
Next i 
Exit Sub 
On Error GoTo 0 
 
noSelections: 
 MsgBox "There are no previous selections"

[!includeSupport and feedback]