+ Reply to Thread
Results 1 to 5 of 5

Why did an inner loop variable start overwriting the outer loop range suddenly?

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Why did an inner loop variable start overwriting the outer loop range suddenly?

    This is a very strange error but hopefully someone here can explain the reasons why it's happening.

    Please Login or Register  to view this content.
    In the above code I used to be able to redefine last_Row inside my For loop with no issues. Recently though the inner variable is now redefining my outer loop. The only change I can think of is that 2010 is somehow smarter than 2007 which I was using previously. Can anyone confirm or deny this?

  2. #2
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Why did an inner loop variable start overwriting the outer loop range suddenly?

    Place the last_Row= Worksheets("Sheet1").Range("A65536").End(xlUp).Row before the outer loop

  3. #3
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Why did an inner loop variable start overwriting the outer loop range suddenly?

    I think you are missing my point.

    Please Login or Register  to view this content.
    The above is closer to what the code looks like. I define last_Row for the outer loop. In the inner loop I used to be able to redefine last_Row and my outer loop wouldn't be affected. In other words, I could define a last_Row on "Sheet2" and a different last_Row on "Sheet1". Weird right?

    Another issue I've just seen pop up is pasting values to a hidden but not very hidden worksheet. Previously I could do this but apparently not anymore.

    : /

    Excel you confuse me.

  4. #4
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Why did an inner loop variable start overwriting the outer loop range suddenly?

    Rename your second last row as new_lastRow and replace it in the for y=1 to new_lastRow

  5. #5
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Why did an inner loop variable start overwriting the outer loop range suddenly?

    Yea, that was basically my solution but isn't an answer to my question. Excel is changing functionality on me from session to session and I am guessing it is something with 2007 to 2010 but I don't know for sure.

+ 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