+ Reply to Thread
Results 1 to 13 of 13

Loop to Delete Entire.Rows if conditions are met

  1. #1
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Loop to Delete Entire.Rows if conditions are met

    Hi

    I am looking for a way to delete Entire.Rows in excel if certain conditions are met. I have tried writting code but seeing as I am moderate this one is a little too advanced for me, a sample spreadsheet is attached for your reference.

    The conditions is:
    If any particuliar Row has the same Price (column M) & same Billing Account (Column J) & same Contract (column AA) as another row [/I] THEN simply delete the Entire Row where there is text found in Column AC

    It may sound complicated, but with the sample spreadsheet it is easy to follow. Basically I am trying to delete the dup that occurs, I am dealing with thousands of rows of data so can't manually do this.

    To sum up:
    If a Particular Client has a case where the Account & Price & Contract are the same, I need one of the lines deleted, the line that would be deleted is the one with text found in AC. I originally had a macro to delete all rows with text in AC, but it was deleting stuff that wasn't dups, this is why I need to encorprate these conditions.

    In my sample spreadsheet I highlighted in blue where this situation would happen, and if I were to run a macro it should only delete 2 lines, one from each case. ** in real spreadsheet rows where this dups appears may not neccesarily be adjacent to each other

    This is a little too advanced for me, I will take whatever help I get and learn off you for next time. Greatly appreciate anyone helping me out.

    Have a bless day.
    Attached Files Attached Files
    Last edited by stein7; 11-28-2018 at 09:45 PM.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Loop to Delete Entire.Rows if conditions are met

    Hi and welcome to the forum,

    Here's a suggestion. The code is simple, you should be able to understand it.
    The idea is to store the "unique" values in a dictionary

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Loop to Delete Entire.Rows if conditions are met

    Will the duplicates always be in adjacent rows as you have in your example?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Re: Loop to Delete Entire.Rows if conditions are met

    no they don't appear like this always

  5. #5
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Re: Loop to Delete Entire.Rows if conditions are met

    Quote Originally Posted by GC Excel View Post
    Hi and welcome to the forum,

    Here's a suggestion. The code is simple, you should be able to understand it.
    Thank you and wow this is something I will need to learn, I like this dictionary. Thank you kindly

  6. #6
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Loop to Delete Entire.Rows if conditions are met

    Note :
    the code will work as long as the row to keep (without the text in AC) always appear first.
    If that's not the case, the code will have to be modified.

  7. #7
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Re: Loop to Delete Entire.Rows if conditions are met

    Quote Originally Posted by GC Excel View Post
    Note :
    the code will work as long as the row to keep (without the text in AC) always appear first.
    If that's not the case, the code will have to be modified.
    Oh no GC this is not the case in my actual spreadsheet... Sometimes they are 5 rows apart with other data in between. Do you have any suggestions to go about solving this. I greatly appreciate it if you know a work around

  8. #8
    Registered User
    Join Date
    02-22-2016
    Location
    Harare, Zimbabwe
    MS-Off Ver
    2007 & 2010
    Posts
    71

    Re: Loop to Delete Entire.Rows if conditions are met

    @ GC Excel

    Hello GC Excel,

    I like your Dictionary deploy. May we add in Columns.Autofit?

    Please Login or Register  to view this content.
    Cheers.
    Happy? Click the * to the left.

  9. #9
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Re: Loop to Delete Entire.Rows if conditions are met

    Unfortunately that doesn't solve deleting the duplicate if they aren't adjacent

  10. #10
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Loop to Delete Entire.Rows if conditions are met

    Hi,

    no worries, there's always a solution in Excel.
    Logic of the code is slightly changed... see below.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop to Delete Entire.Rows if conditions are met

    Here's a block deletion adaptation of GC's code:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Loop to Delete Entire.Rows if conditions are met

    Here's a speed improvement adaptation of xladept's adaptation of GC's code.

    The Input data is read en masse into an array (for speed) and then the array is processed.
    Also, a logic change to delete the duplicate with the sting if it occurs first or second.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 11-29-2018 at 08:03 AM. Reason: typo

  13. #13
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,285

    Re: Loop to Delete Entire.Rows if conditions are met

    Please Login or Register  to view this content.
    Last edited by daboho; 11-29-2018 at 09:08 AM.

+ 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] Loop through Column & delete entire row if Value is found
    By lougs7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2018, 02:56 PM
  2. [SOLVED] Delete Entire rows without loop with multiple partial strings criteria
    By caabdul in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-04-2018, 12:05 PM
  3. [SOLVED] Help combining macros to delete rows on conditions and add data into cells on conditions
    By JayJayGC in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-03-2017, 10:14 AM
  4. [SOLVED] Copying and Pasting entire rows on conditions
    By Nuccio92 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2015, 02:01 PM
  5. Delete entire rows
    By Solberto in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-06-2015, 02:29 PM
  6. [SOLVED] Loop through worksheet add and delete row with conditions
    By Hyperdude in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-09-2012, 12:05 AM
  7. [SOLVED] Macro to select 4 entire rows and then delete rows
    By Scott Viney in forum Excel General
    Replies: 3
    Last Post: 09-22-2005, 03:05 PM

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