+ Reply to Thread
Results 1 to 7 of 7

Error 92: For Loop Not Initialized - It worked before??

  1. #1
    Registered User
    Join Date
    06-16-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Error 92: For Loop Not Initialized - It worked before??

    Morning,
    I'm having an issue with the below code, i did work once, but suddently gave the error in the title on the For loop starting "For Each family In families()". i cant figure it out, after googling people suggested using option Explicit, which i have but it still doesnt work, ive declared all variables also. Strangely, it does give the result i want it to, but i just get this error every time ??


    Please Login or Register  to view this content.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Error 92: For Loop Not Initialized - It worked before??

    Hi,
    but i just get this error every time ??
    Let's look at this line of code:
    Please Login or Register  to view this content.
    It's sitting inside a sequence of If...End If blocks, which means that it will only be called when certain conditions are met.

    families is a dynamic array. If the ReDim statement isn't called then families is not dimensioned. If it isn't dimensioned then you can't use a For Each... Next loop to iterate through it, so you get that "For Loop Not Initialized" runtime error. Here is a simple example to illustrate:
    Please Login or Register  to view this content.

    So, you essentially have two options to fix the problem. You could either restructure your code to ensure ReDim is called, or you could devise a test to ensure that the array has been dimensioned. (larger code re-write or errorhandling are also options).
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    06-16-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Error 92: For Loop Not Initialized - It worked before??

    Thanks Colin, but i also get this error when i know the Array has been re-dimensioned as it outputs the data from the array ?

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Error 92: For Loop Not Initialized - It worked before??

    Hi - can you attach an example for us to see?

  5. #5
    Registered User
    Join Date
    06-16-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Error 92: For Loop Not Initialized - It worked before??

    Upload feature of forum is bugging out. ive placed it on my webserver, see link below.

    ftp://ftp.davidjlittle.co.uk/htdocs/downloads/TMP condensed daves calc NEW.xlsm

  6. #6
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Error 92: For Loop Not Initialized - It worked before??

    When I click on your link I get this:
    Matrix FTP server ready.
    This is a private system - No anonymous login
    IPv6 connections are also welcome on this server.
    I could rewrite the code, but I would prefer to help you to understand why you are getting the error.

  7. #7
    Registered User
    Join Date
    06-16-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Error 92: For Loop Not Initialized - It worked before??

    Buggy upload wont let me attach the file even though its well within file limit for Zip

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1