+ Reply to Thread
Results 1 to 6 of 6

Invalid Next control variable reference

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    Regina
    MS-Off Ver
    Excel 2010
    Posts
    4

    Invalid Next control variable reference

    Hey There,

    I am brand new to this forum but I was wondering if anyone can help. I keep receiving an Invalid Next control variable reference. I'm trying to completely automate an email system, I'm one final step away! I've attached my code, I keep receiving the error at the "Next Fnum" stage at the very end of the code..

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Invalid Next control variable reference

    It looks like you're using Fnum for 2 different methods - e.g. you have an IF statement that checks an open variable fnum, then you try to also use the same variable in a for/next loop. Try changing all the fnum's used in the for/next loop and next fnum to a unique variable name (xyz).

  3. #3
    Registered User
    Join Date
    05-31-2012
    Location
    Regina
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Invalid Next control variable reference

    On a risk of sounding dumb, how exactly could I do that?

  4. #4
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Invalid Next control variable reference

    No dumb questions And actually, taking a look at this it looks like you might just have your If / End if statements placed incorrectly - e.g. you're invalid next because it can't find your initial for. If you look at your code you have 2 next/for loops. However, you 2 beggings for your foor loops (e.g. For fnum... and For each cell), but you only have 1 ending Next fnum.

    Just like your If Then / End if statements have a beginning/end, so do your for/next loops.

    You need to close the loop on your other For each cell loop. I'm not sure where you want that to end though. Read through your code carefully and make sure your if/end if statements are setup properly and that your for/next loops all close and process exactly what you want each of them to do.

  5. #5
    Registered User
    Join Date
    05-31-2012
    Location
    Regina
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Invalid Next control variable reference

    Thanks MedPack! With your help I was able to figure out where the problem was by making sure the For/Next and If statements lined up correctly. Unfortunately the code was not doing exact what I hoped it would. I will be posting a new thread and closing this one to figure out how I can set this up to CC all email addresses in one of my worksheet columns. Thanks for your help!

  6. #6
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Invalid Next control variable reference

    Nice, glad you were able to figure out and no problem, happy to help .

+ 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