Delete Range if duplicate value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a list of names in column B row 1 thru 50 of a worksheet. I would like to search the column for duplicate values in column B only and remove any duplicates. I also have data below the search range that I would like to stay in cell B200. I have tried some codes from previous posts, but they all either searched on column A or you had to select the column before you started the macro also any data below the search area was brought up by the amount of rows deleted

Thanks for you help
 
Hi
try the following macro (borrowed from
http://www.cpearson.com/excel/deleting.htm#DeleteDuplicateRows):
Public Sub DeleteDuplicateRows()

Dim Col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Col = ActiveCell.Column

Set Rng = ActiveSheet.Range("B1:B199")


N = 0
For r = 199 To 1 Step -1
V = Rng.Cells(r, 2).Value
If Application.WorksheetFunction.CountIf(Rng,V) > 1 Then
Rng.Rows(r).EntireRow.ClearContents
N = N + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


After this select the rows 1:199 and sort them so that you move the
blank lines down
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top