+ Reply to Thread
Results 1 to 5 of 5

For each cell in range loop does not recognize expanding range

  1. #1
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    For each cell in range loop does not recognize expanding range

    Help!!!

    Have the following code:

    Please Login or Register  to view this content.
    Essentially it deletes all but first (top) cell in a named range (panel_sort) and rebuilds it (just in case there are any changes in source data). It works fine for the first set of loops to lookup the first cell in the source data and return vlaues indexed one column to left and put those values in the named range. The next step is to do a lookup of the second cell in the named range... but the For Each loop doesn't recognize that the named range has grown since the first loop.

    Being a VBA noob, I don't know how to fix it....
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: For each cell in range loop does not recognize expanding range

    Please Login or Register  to view this content.
    Okay, just realized "Delete" should be "ClearContents".

    But that's not a fix for the topic problem...

  3. #3
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: For each cell in range loop does not recognize expanding range

    I think I solved it myself...

    Please Login or Register  to view this content.
    Any of you VBA gurus see any mistakes, or better method...???

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: For each cell in range loop does not recognize expanding range

    Hi jhren,

    Why don't you use a Dynamic Named Range on your sheet to give you the number of rows.

    see http://www.ozgrid.com/Excel/advanced-dynamic-ranges.htm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: For each cell in range loop does not recognize expanding range

    Range "panel_sort" is a dynamic named range. That's part of the original problem. The first part of the code drops "panel_sort" to a one cell range. That's all the For Each loop sees, even though "panel_sort" grows during the loop. With a Do While loop, the growth registers on successive passes.

    Didn't try a For Each loop based on "panel_sort" row count, because the Do While loop I tried worked.
    Last edited by jhren; 07-07-2013 at 07:56 AM.

+ 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