Microsoft Knowledge Base

XL: Incorrect Error Message: "For Without Next"

Last reviewed: September 13, 1996
Article ID: Q120800
The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0, 5.0c
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for the Macintosh, version 5.0

SUMMARY

In Microsoft Excel for Windows versions 5.x and 7.0, you may receive the following error message

   For Without Next

even when you do have the Next statement that concludes a For loop.

MORE INFORMATION

The "For Without Next" error message is generated if Visual Basic, Applications Edition, detects that a For loop has been started but the Next statement is not present to end the loop. It is also generated erroneously if you have an End If statement within the For-Next loop.

Steps to Reproduce Problem

Enter the following on a module sheet:

   Sub Test()
      For X = 1 To 2
         End If
      Next
   End Sub

If you try to run this code, you get the following error message:

   For without Next

The proper error message should be:

   End If without Block If

REFERENCES

"Visual Basic User's Guide," pages 139-140, 145-146


KBCategory: kbother
KBSubcategory:

Additional reference words: 5.00 5.00c 7.00 for next



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 13, 1996
©1997 Microsoft Corporation. All rights reserved. Legal Notices.