+ Reply to Thread
Results 1 to 5 of 5

VB Code To Delete Rows between 2 flags on loop

  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    3

    VB Code To Delete Rows between 2 flags on loop

    Hello and thanks in advance for any help.

    I am trying to to put something together that will search through column AA:AA and if it finds a specific flag(Ex: "1") it will delete all rows under it until it hits another flag(Ex:"2"). I would want this to loop all the way through the sheet which does not have a defined amount of rows each time. Basically any data after a 1 should be removed and any data after a 2 should be kept in tact. Is there a way to set this up and also loop through the entire colum?

  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: VB Code To Delete Rows between 2 flags on loop

    You could probably do it without a loop.

    Just find the first row in AA with the "1" and then find the next row after that with the "2", then delete all the rows inbetween.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-07-2012
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VB Code To Delete Rows between 2 flags on loop

    There are multiples of these. I have a code that locates a specific word and tags a 1 to the column and also tags a 2 based on another word. Each of these has multiple rows under them and I want to keep all data associated with the 2's. It would like like this below hopefully that will help I would want anything that is a 1 and the following rows deleted but anything that has a 2 and its rows would need to stay intact.

    1
    X
    X
    X
    2
    X
    X
    X
    2
    X
    X
    1
    X
    X
    1
    X
    X
    X
    2

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VB Code To Delete Rows between 2 flags on loop

    Hi shauncol3,

    As long as the data starts in row 2, try the following (though initially on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VB Code To Delete Rows between 2 flags on loop

    Sorry, my bad
    Last edited by Trebor76; 12-08-2012 at 07:48 PM.

  6. #6
    Registered User
    Join Date
    12-07-2012
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VB Code To Delete Rows between 2 flags on loop

    Oh man yes that worked perfectly thank you both for helping me on this...you guys are legit

+ 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