Is it possible to remove duplicates from a range of cells? Via macro! I.e. if a document contains a list of names and data, and name appears more than once, delete than name and the associated data coluns to the right and left?
All the best Alan
Is it possible to remove duplicates from a range of cells? Via macro! I.e. if a document contains a list of names and data, and name appears more than once, delete than name and the associated data coluns to the right and left?
All the best Alan
Last edited by ad9051; 06-20-2011 at 01:18 PM.
Alan,
Give this a try:
Sub DeleteDuplicatesMacro_for_ad9051() Const NamesCol As String = "A" Const StartRow As Long = 2 Dim rngDuplicates As Range: Set rngDuplicates = Nothing Dim RowIndex As Long For RowIndex = Range(NamesCol & Rows.Count).End(xlUp).Row To StartRow + 1 Step -1 If WorksheetFunction.CountIf(Range(NamesCol & StartRow, NamesCol & RowIndex - 1), Range(NamesCol & RowIndex)) > 0 Then If rngDuplicates Is Nothing Then Set rngDuplicates = Range(NamesCol & RowIndex) Else Set rngDuplicates = Application.Union(rngDuplicates, Range(NamesCol & RowIndex)) End If End If Next RowIndex If Not rngDuplicates Is Nothing Then rngDuplicates.EntireRow.Delete xlShiftUp End Sub
Hope that helps,
~tigeravatar
I am a big fan of tiger avatar, ill give it a whirl! Cheers Alan
Works many thanks Alan
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks