Results 1 to 4 of 4

Delete Duplicate Rows, if column does not contain x

Threaded View

JulieQ Delete Duplicate Rows, if... 11-13-2015, 09:44 PM
Trebor76 Re: Delete Duplicate Rows, if... 11-13-2015, 11:09 PM
Philb1 Re: Delete Duplicate Rows, if... 11-14-2015, 07:16 AM
JulieQ Re: Delete Duplicate Rows, if... 11-23-2015, 04:08 PM
  1. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Delete Duplicate Rows, if column does not contain x

    Hi Julie,

    Try this macro (though initially on a copy of your data as the results cannot be undone if they're not as expected) while on the sheet with the data:

    Option Explicit
    Sub Macro1()
    
        Dim lngLastRow As Long
        Dim lngLastCol As Long
        Dim lngMyRow As Long
        Dim lngMyCol As Long
        Dim strMyCol As String
        
        Application.ScreenUpdating = False
        
        lngLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        lngLastCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
        
        With Range(Cells(2, lngLastCol + 1), Cells(lngLastRow, lngLastCol + 1))
            .Formula = "=IF(AND(TRIM(D2)<>""Closed"",TRIM(D2)<>""Abandoned""),A2&B2,"""")"
            .Value = .Value
        End With
            
        strMyCol = Left(Cells(1, lngLastCol + 1).Address(True, False), Application.WorksheetFunction.Search("$", Cells(1, lngLastCol + 1).Address(True, False)) - 1)
            
        With Range(Cells(2, lngLastCol + 2), Cells(lngLastRow, lngLastCol + 2))
            .Formula = "=IF(" & strMyCol & "2<>"""",COUNTIF($" & strMyCol & "$2:$" & strMyCol & "$" & lngLastRow & "," & strMyCol & "2),"""")"
            .Value = .Value
        End With
            
        For lngMyRow = lngLastRow To 2 Step -1
            If Val(Cells(lngMyRow, lngLastCol + 2)) > 1 Then
                Rows(lngMyRow).EntireRow.Delete
            End If
        Next lngMyRow
        
        For lngMyCol = lngLastCol + 2 To lngLastCol + 1 Step -1
            Columns(lngMyCol).EntireColumn.Delete
        Next lngMyCol
        
        Application.ScreenUpdating = True
        
        MsgBox "Done"
    
    End Sub
    Regards,

    Robert
    Last edited by Trebor76; 11-13-2015 at 11:11 PM.
    ____________________________________________
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Delete entire Rows if Column value is unique OR Duplicate is less than three
    By analystbank in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2014, 12:09 PM
  2. Replies: 5
    Last Post: 11-12-2012, 08:38 PM
  3. Replies: 4
    Last Post: 01-25-2011, 08:03 PM
  4. Replies: 5
    Last Post: 06-11-2009, 08:57 AM
  5. Replies: 2
    Last Post: 01-13-2009, 01:42 PM
  6. [SOLVED] Is there a quick way to delete all duplicate rows in a column?
    By Jellaby in forum Excel General
    Replies: 3
    Last Post: 05-16-2005, 06:06 PM
  7. [SOLVED] I want to delete rows with duplicate entries within one column.
    By kini olegario in forum Excel General
    Replies: 1
    Last Post: 01-14-2005, 10:07 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