Check duplicates in one coloumn and delete duplicate row

manoj_arsul

Board Regular
Joined
Jun 27, 2018
Messages
61
Hi,

I want to run program for find duplicate values in column "A" , & delete all those row which are duplicates values in Column "A"
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi,

I want to run program for find duplicate values in column "A" , & delete all those row which are duplicates values in Column "A"
Have a nice day ;)
Code:
Sub RemoveDubs()
    ActiveSheet.Range("$A:$A").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
 
Upvote 0
Hi,

I want to run program for find duplicate values in column "A" , & delete all those row which are duplicates values in Column "A"
Can you confirm ..
- Whether or not you have other columns of data on the sheet and, if so, if you want the entire row removed from the sheet for duplicates in column A?
- Whether your data has headings or not?
- About how many rows of data are you likely to have in your sheet?
- For the sample below, whether you want rows 3:7 all deleted or just rows 5:7, leaving a single occurrence of each value?


Book1
A
1Hdr 1
2a
3b
4c
5b
6c
7c
8d
Delete Dupes
 
Upvote 0
Hi @Peter_SSs

Thank u for your reply !!!

I want run program for below data

A B C
1 A X
2 B y
1 C Z
2 D a
5 E b
1 G C
3 H G
4 I H
1 J I

Output :
A B C
1 A X
2 B y
5 E b
3 H G
4 I H
 
Upvote 0
I want run program for below data
OK, try this with a copy of your workbook.
Code:
Sub RemoveDupes()
  Dim d As Object
  Dim a, b
  Dim nc As Long, i As Long, k As Long
  
  Set d = CreateObject("SCripting.Dictionary")
  nc = Cells.Find(What:="*", After:=Cells(1, 1), LookIn:=xlValues, SearchOrder:=xlByColumns, _
                SearchDirection:=xlPrevious, SearchFormat:=False).Column + 1
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If d.exists(a(i, 1)) Then
      b(i, 1) = 1
      k = k + 1
    Else
      d(a(i, 1)) = 1
    End If
  Next i
  If k > 0 Then
    Application.ScreenUpdating = False
    With Range("A1").Resize(UBound(a), nc)
      .Columns(nc).Value = b
      .Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlNo
      .Resize(k).EntireRow.Delete
    End With
    Application.ScreenUpdating = True
  End If
End Sub
 
Last edited:
Upvote 0
Hi @Peter_SSs

Thank u for your reply !!!

I want run program for below data

A B C
1 A X
2 B y
1 C Z
2 D a
5 E b
1 G C
3 H G
4 I H
1 J I

Output :
A B C
1 A X
2 B y
5 E b
3 H G
4 I H
Code:
Sub RemoveDubs()
    ActiveSheet.Range("$A:$A").RemoveDuplicates Columns:=3, Header:=xlNo
End Sub
 
Upvote 0
OK, try this with a copy of your workbook.
Code:
Sub RemoveDupes()
  Dim d As Object
  Dim a, b
  Dim nc As Long, i As Long, k As Long
  
  Set d = CreateObject("SCripting.Dictionary")
  nc = Cells.Find(What:="*", After:=Cells(1, 1), LookIn:=xlValues, SearchOrder:=xlByColumns, _
                SearchDirection:=xlPrevious, SearchFormat:=False).Column + 1
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If d.exists(a(i, 1)) Then
      b(i, 1) = 1
      k = k + 1
    Else
      d(a(i, 1)) = 1
    End If
  Next i
  If k > 0 Then
    Application.ScreenUpdating = False
    With Range("A1").Resize(UBound(a), nc)
      .Columns(nc).Value = b
      .Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlNo
      .Resize(k).EntireRow.Delete
    End With
    Application.ScreenUpdating = True
  End If
End Sub



also one request , If i want run this program on different sheet then ,

eg. I am on sheet1 and i want run this program for sheet2 or sheet3
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top