+ Reply to Thread
Results 1 to 6 of 6

Do While Nested Loops

  1. #1
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    Excel 365
    Posts
    129

    Do While Nested Loops

    Hello,

    I'm struggling with a nested loop and could use some help/guidance on. I have a sheet with a random amount of data (see attached). My goal is to insert a row and concatenate some text based on the cell below its' value. The below code kind of does this portion, but it stops working when it gets to numbers for some reason (i.e. for some reason, when I run the code it is not determining the difference between "1" or "2", but it is recognizing all the other changes in values. This is basically part 2 of the nest.

    Part 1 of the nested loop requires me to ignore everything from "StartHeader" through "N" so any values in between will just pass a row count + 1. Once the macro reaches "N" it will know to automatically insert a row below "N" and concatenate "Page " and the value of the Cell immediately below this new line and then move on to the next row and check it's value against the previous row.

    Once it detects a change, it again adds a new line and concatenates "Page" and the value of the cell immediately below.

    This continues until we reach "StartHeader" where we basically don't do anything until we get back to "N".

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Do While Nested Loops

    Are these going to be numbers and text?
    Right now you have the entire column formatted as text

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Do While Nested Loops

    This is a two fold code, first code will insert the blanks, then call the second code to insert the "Section" part.

    Please Login or Register  to view this content.
    See attached sample
    Attached Files Attached Files

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Do While Nested Loops

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Do While Nested Loops

    This is a messy code, but it works if I'm not mistaken to get what you mean :
    Please Login or Register  to view this content.
    Oopss... sorry, I didn't realize that what you want is to insert entire row .

    Here is the code which do the insert.
    Please Login or Register  to view this content.
    This code is assuming that each "number" has the same value. For example :
    the number "1" in your example (under page 1 of n) value is 1_aaa, the next row is also 1_aaa
    So if the number "1" value is : 1_aaa, 1_aab, and so on, the code will fail
    because the code doesn't check the number but the value.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by karmapala; 05-10-2020 at 10:29 AM.

  6. #6
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    Excel 365
    Posts
    129

    Re: Do While Nested Loops

    This was absolutely perfect! Thank you so much.

    Thanks to everyone who responded. Some good code in all of them that I should be able to utilize down the road!

+ 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] Help with nested loops
    By wishmaker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-23-2013, 11:03 AM
  2. Nested Loops
    By christian2012 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-10-2013, 08:19 PM
  3. nested loops
    By short_n_curly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2012, 11:10 AM
  4. Nested Do Loops
    By ross88guy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2010, 09:10 AM
  5. VBA - Nested loops
    By roheba in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-09-2010, 01:42 PM
  6. [SOLVED] Nested with loops
    By Clair in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2006, 03:35 PM
  7. [SOLVED] nested loops
    By jer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2006, 05:15 PM

Tags for this Thread

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