Excel: Selecting a Variable Range Through a Macro

Last reviewed: November 30, 1994
Article ID: Q21585

SUMMARY

To select a variable range of cells on a Microsoft Excel for the Macintosh version 1.0, 1.03, 1.04, 1.06, 1.5, 2.2, or 3.0 spreadsheet using a macro, use the SELECT and OFFSET functions. For example, to select the absolute cell range corresponding to integer variables defined (with the SET.NAME function) as FirstRow, FirstCol, LastRow, and LastCol, use the following formula in your macro:

=SELECT(OFFSET(!A1,FirstRow-1,FirstCol-1,LastRow-FirstRow,LastCol- FirstCol))

The following formula would also work; however, the above formula is faster:

   =SELECT("R"&FirstRow&"C"&FirstCol&":R"&LastRow&"C"&LastCol)

For more information about selecting cells through a macro, query on the following words:

   Excel and SELECT and OFFSET

For more information about using the OFFSET function with Excel for the Macintosh, see pages 163-164 in the "Microsoft Excel Function Reference" version 3.0 manual. If you are using Excel 2.2, see page 251 in the "Microsoft Excel Functions and Macros" version 2.2 manual.

Note: This article also applies to Microsoft Excel for Windows and Microsoft Excel for OS/2 versions 2.1 (2.2) and 3.0 on both platforms.


KBCategory: kbother
KBSubcategory:

Additional reference words:


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: November 30, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.