+ Reply to Thread
Results 1 to 6 of 6

Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

Hybrid View

Orangeworker Macro To Delete Duplicate... 10-09-2010, 09:54 AM
davesexcel Re: Macro To Delete Duplicate... 10-09-2010, 10:33 AM
MarvinP Re: Macro To Delete Duplicate... 10-09-2010, 10:44 AM
Orangeworker Re: Macro To Delete Duplicate... 10-09-2010, 10:53 AM
Orangeworker Re: Macro To Delete Duplicate... 10-09-2010, 11:00 AM
MarvinP Re: Macro To Delete Duplicate... 10-09-2010, 12:37 PM
  1. #1
    Registered User
    Join Date
    03-04-2010
    Location
    South Florida
    MS-Off Ver
    Excel 2007
    Posts
    72

    Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

    Hi,

    I'm looking for a simple macro to delete duplicate records (rows in Excel), but omit two columns of information in the selection. Columns that need to be included are (A > H). The columns that I need the macro to omit are (E & F).

    Thanks,
    Henry

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

    Re: Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

    Try this it Finds the duplicates in Column A but just deletes A1:D1,G1:H1 Ranges and shifts the cells up
    Sub DeleteDuplicates()
    
        Dim x As Long, LastRow As Long, c As Range
    
        LastRow = Range("A65536").End(xlUp).Row
        
        For x = LastRow To 1 Step -1
        
            If Application.WorksheetFunction.CountIf(Range("A1:A" & x), Range("A" & x).Text) > 1 Then
            
                Set c = Range("A" & x)
                c.Range("A1:D1,G1:H1").Delete Shift:=xlUp
                
            End If
            
        Next x
    
    End Sub

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,372

    Re: Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

    Hi Orangeworker,

    There is a remove duplicates feature in Excel 2007 and 2010. It is under the Data tab in 2010. When run it asks which columns of data to match to be considered a duplicate. What you want may already be built into Excel.

  4. #4
    Registered User
    Join Date
    03-04-2010
    Location
    South Florida
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

    Hi and thanks for both replys. Yes, I've used the remove duplicate feature under the data tab before, but for some reason, even if I uncheck certain columns, it still doesn't give me the result I need for some reason.

  5. #5
    Registered User
    Join Date
    03-04-2010
    Location
    South Florida
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

    Marvin, thanks for the code. I haven't tried it yet, but their is going to be a lot of the same data in column A as well as column B, for example. So I need to treat each row as a "record". Do you think it will work based on this info? I'm getting ready to head back to my office now, then I will try it out.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,372

    Re: Macro To Delete Duplicate Records (Rows), While Omiting Specific Columns

    Understanding what you think is happening compared to how Excel handles it is my ongoing obsession.

    Give it a try and see what happens. It may already be built in. Make backups!

+ 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