delete unique values in column

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
750
Office Version
  1. 365
  2. 2010
so in column D, i have unique and duplicates, but i want a macro that deletes the unique values and thus leaving only the duplicates.

the data set, just fyi, is from column A to K.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this
Assuming your data starts in row 1

Code:
Sub Delete_Rows()
  Dim lr As Long, i As Long, a() As Variant, r As Range, rng As Range
  Application.ScreenUpdating = False
  lr = Range("D" & Rows.Count).End(xlUp).Row
  Set rng = Range("D1:D" & lr)
  Set r = Range("D" & lr + 1)
  a = rng.Value
  For i = 1 To UBound(a)
    If WorksheetFunction.CountIf(rng, a(i, 1)) = 1 Then
      Set r = Union(r, Range("A" & i))
    End If
  Next i
  r.EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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