+ Reply to Thread
Results 1 to 6 of 6

VBA code to delete duplicate rows based on multiple conditions

  1. #1
    Registered User
    Join Date
    06-26-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2011
    Posts
    6

    VBA code to delete duplicate rows based on multiple conditions

    Hello,

    I would like to create a VBA code that will delete rows if they are the same as a previous row. However, not all of the data may be the same throughout all of the rows so I need to be specific about the columns that will be used to see if the rows are the same. The columns that I would like to see if there is a match is the code, date, data 1, and data 2. If all of these criteria are the same for any of the other rows on the sheet, I would like them deleted. I have attached a small sample. In the sample the code should result in either row 2 or row 3 being deleted. Thank you for your help.
    Attached Files Attached Files
    Last edited by pjsween; 06-27-2012 at 10:17 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA code to delete duplicate rows based on multiple conditions

    f all of these criteria are the same for any of the other rows throughout the workbook I would like them deleted.
    Do you mean the macro should check if all the sheets are populated with data and then run the macro?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-26-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2011
    Posts
    6

    Re: VBA code to delete duplicate rows based on multiple conditions

    I would like it to just check the single sheet that all the data is on. Sorry about that.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA code to delete duplicate rows based on multiple conditions

    I understand that you have given these 4 columns for the sample file. Does your original file also have these 4 columns or are there many more?

  5. #5
    Registered User
    Join Date
    06-26-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2011
    Posts
    6

    Re: VBA code to delete duplicate rows based on multiple conditions

    There are two additional columns before the code column. I have attached an excel file.
    Attached Files Attached Files

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA code to delete duplicate rows based on multiple conditions

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button.

+ 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