Excel: Increasing Efficiency in Looping Over a Region of Cells

Last reviewed: April 3, 1997
Article ID: Q51843
2.20 MACINTOSH kbother

The information in this article applies to:

  • Microsoft Excel for the Macintosh, version 2.2

SUMMARY

In Microsoft Excel, when you need to loop over a region of cells (such as to perform some repetitive operation), use the OFFSET() or INDEX() command instead of concatenating a reference string.

The typical macro written to loop over a region of cells may look like the following:

   =FOR("i",1,10)
   =FORMULA("10","TEST.XLS!R"&i&"C1")
   =NEXT()

The above macro can be replaced by the faster version shown below:

   =FOR("i",0,9)
   =FORMULA("10",OFFSET(TEST.XLS!R1C1,i,0))
   =NEXT()

MORE INFORMATION

This information was taken from page 153 of the "Microsoft Excel Technical Reference for the Macintosh," which can be obtained by calling Microsoft End User Sales and Service at (800) 426-9400.

Note: Page 153 displays an incorrect example of the loops because it does not include the parentheses after the NEXT() statement.


KBCategory: kbother
KBSubcategory:

Additional reference words: 2.2 2.20 docerr


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: April 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.