+ Reply to Thread
Results 1 to 6 of 6

Problems with nested loop to copy a range

  1. #1
    Registered User
    Join Date
    04-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    11

    Problems with nested loop to copy a range

    Hi

    I have a problem with a nested loop. I know there is something wrong in it, but cannot figured out what this is. Can you help me with this?
    The code have to look if a cell contains something, if so then that cell + 5 have to be copied from sheet 2 into sheet 11.
    After that it have to look at the next cell and do the same thing but then past it next to the previous range.
    The problem is within the loop because it works when I am using the range like this: Sheet11.Range("R7:AC7,R22:AC22,R37:AC37.....until... R352: AC352").SpecialCells(xlCellTypeBlanks).Cells(1).Select
    But I need a range until R865: AC865. But when I am using that excel cannot handle such a long range.
    The same is the problem at the second part of the code


    The VBA code is following:

    Please Login or Register  to view this content.
    Kind regards
    Last edited by Edejager; 04-04-2013 at 10:41 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Problems with nested loop to copy a range

    attach a sample file for testing
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    04-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Problems with nested loop to copy a range

    Sorry, here is the file.
    It was to big to post it unzipped.

    The sub that give the problem is written in module16.

    Labflow Lite.zip

    Thanks a lot

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Problems with nested loop to copy a range

    very strange formatting on sheet LabFlow Lite Sequencing, the error is due to the SpecialCells method
    why the strange formatting ?
    why do you use SpecialCells method ?
    if you eliminate it the code works

  5. #5
    Registered User
    Join Date
    04-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Problems with nested loop to copy a range

    Thanks a lot the code works indeed,
    but the problem now is that only the last selected cells are copied. And not start at cell "U5" and copy each range to the other sheet.
    So first U5:U10 then V5:V10 and so on..
    And every time a range is coppied excel have to look if the target cell is empty. therefore I used the specialCells method.

    Thanks again

  6. #6
    Registered User
    Join Date
    04-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Problems with nested loop to copy a range

    Hi

    I have now changed the loop (a loop within the if section) this will work better.
    Also I will edit the range so the problem is a kind of solved
    Thanks a lot patel45 for your answers

    Kind regards

+ 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