Making a Multiple Selection from a Macro in Excel

Last reviewed: September 2, 1997
Article ID: Q76692

The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 4.0a, 5.0
  • Microsoft Excel for OS/2, versions 2.2, 3.0
  • Microsoft Excel for the Macintosh version 2.x, 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("R1C1:R5C1,R1C3:R5C3")

REFERENCES

"Function Reference," version 4.0, pages 378-381

"Microsoft Excel Function Reference," version 3.0, pages 209-212

"Microsoft Excel Functions and Macros," for Windows version 2.1, pages 348-349

"Microsoft Excel for OS/2 Functions and Macros," version 2.2, pages 354-355


Additional query words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.0
3.00 4.0 4.00 5.00
Keywords : PgmHowTo PgmOthr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.