+ Reply to Thread
Results 1 to 6 of 6

Nested For...Next Loop, Invalid Next control variable reference Error

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Nested For...Next Loop, Invalid Next control variable reference Error

    Hi,
    Im still new in VBA.
    I tried to do the next iteration in the "nested for..next loop". Here is my attempt in doing it. But there's an error

    Compiler complains : Invalid Next control variable reference

    Could anyone help me with this?

    Thanks in advance.


    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    08-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    573

    Re: Nested For...Next Loop, Invalid Next control variable reference Error

    First Next j should come rite? The inner for loop is "j"..
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Nested For...Next Loop, Invalid Next control variable reference Error

    i tried but there's still error.. What i'm trying to do is , when this condition "If (Sheet2.Cells(i, 18) <= Date)" met, the DueArray will copy the cell value into the DueArray (1,0),DueArray(1,1),DueArray(1,2). But if the condition = false, I want it to exit the inner j loop, go to next i loop iteration.

    But the problem now is, whenever "If (Sheet2.Cells(i, 18) <= Date)" is TRUE.. it overwrites the data in the DueArray (1,0),DueArray(1,1),DueArray(1,2) instead of going to DueArray (2,0),DueArray(2,1),DueArray(2,2)and so on..

    Could anyone help me with this? i've been spending days to figure out this problem.. Thanks in advance

    Nway, i made some changes to the code..

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    08-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    573

    Re: Nested For...Next Loop, Invalid Next control variable reference Error

    I think you don't need the inner for loop.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Nested For...Next Loop, Invalid Next control variable reference Error

    thanks so much !
    it works..its not that complicated than how i think it is..

  6. #6
    Valued Forum Contributor
    Join Date
    08-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    573

    Re: Nested For...Next Loop, Invalid Next control variable reference Error

    cool.. please make this thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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