+ Reply to Thread
Results 1 to 7 of 7

nested loop problem

  1. #1
    Registered User
    Join Date
    05-06-2011
    Location
    Lutz, FL
    MS-Off Ver
    Excel 2003
    Posts
    4

    nested loop problem

    Hi, i'm trying to get the section of code [For i = 1 to N] through [Next i] to loop within the larger loop. Does anyone know how to do this?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: nested loop problem

    As far as I can see the 1 to N loop is nested within the 1 to NumRows loop.

    What makes you think it isn't?

    Is the code not doing what you want?

    Is it producing incorrect results?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-06-2011
    Location
    Lutz, FL
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: nested loop problem

    In column K I have a list of numbers. I'm trying to copy the first set of numbers in K1 and then paste under the last set of numbers in column A. I also need the number pasted 21 times. Then, I want to go to the next set of numbers in column k and repeat the process until there are no more numbers in column k. The following code works but, i have to keep pushing the macro button 61 times until I've gone through every number set in column k. So, i'm trying to get it so i don't have to keep pressing the macro button over and over again.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: nested loop problem

    I don't think you need the 2nd loop.

    If you want to copy the same thing N no of times use resize.

    For example, something like this.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-06-2011
    Location
    Lutz, FL
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: nested loop problem

    i don't think i put it in the code correctly... it keeps pasting over and over again - looks like its kind of working though.. it just keeps pasting over and over again...

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: nested loop problem

    The code I posted will copy each value from column K and paste them 21 times to column A.

    It's meant to replace your code.

  7. #7
    Registered User
    Join Date
    05-06-2011
    Location
    Lutz, FL
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: nested loop problem

    Oh - sorry about that. I removed my code and your code worked perfect! Thanks so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-14-2014, 09:32 AM
  2. [SOLVED] Having problem with a nested FOR loop
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-03-2014, 04:39 AM
  3. Nested Loop problem/Algorithm
    By Asad74 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2012, 09:36 PM
  4. Next without For error in nested loop - Escaping a Nested Loop?
    By BeneRich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2012, 06:38 PM
  5. For each loop nested; getting stuck on one cell in first iteration of nested loop
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-22-2009, 11:54 AM

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