Microsoft KB Archive/76692

{|
 * width="100%"|

Making a Multiple Selection from a Macro in Excel

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 3.0, 4.0, 4.0a, 5.0
 * Microsoft Excel for OS/2, versions 2.2, 3.0
 * Microsoft Excel for the Macintosh, versions 3.0, 4.0, 5.0

-

SUMMARY
To select multiple ranges on a spreadsheet from a Microsoft Excel macro, it is necessary to separate the ranges you want to select with a comma and either enclose them with a set of parentheses within the SELECT statement, or to enclose the reference in quotation marks.

MORE INFORMATION
The SELECT statement takes two arguments. The first argument is the cell or range of cells you want to select. The second argument is the cell in the range you want to make the active cell.

When using the SELECT statement in a macro to select multiple ranges, it is necessary to enclose the set of ranges in parentheses. Otherwise, the second range will be seen as the second argument to the SELECT statement, resulting in a macro error.

Example
To perform a multiple selection in a Microsoft Excel macro to select ranges A1:A5 and C1:C5 on the active worksheet, use the following SELECT statement in your macro:

  =SELECT((!A1:A5,!C1:C5)) To perform the same action using quoted references, use:

  =SELECT(&quot;R1C1:R5C1,R1C3:R5C3&quot;)