Not simple duplicated values removable

nasrundin

New Member
Joined
Jan 6, 2013
Messages
5
Hi there,

I want to remove duplicated rows from my table. The real spreadsheet is huge, but in order to simplify it, I'm posting here a sample in this picture. It's a spreadsheet with clients, with Names, Ages and Countries. We have full data of most of our clients, but we have duplicated and incomplete rows we want to delete. I tried advanced filter and the duplicate removable bottom from Data menu but either doesn't work.

temp.jpg


To understand better is easier to look at my sample. In this case, I want to delete rows:

3 (because I have row 2 with complete data)
5 (because I have row 6 with complete data)
9 (because I have row 8 with complete data).

IMPORTANT: In this case, I can't just make a normal filter and copy the visible cells to another spreadsheet, because I don't want to delete the row 4, notice that row 4 (José) is not a duplicated row, but it has no data (or incomplete data).

My question is, how can I delete only duplicate data (incomplete/blank), preserving not duplicated rows as the row number 4?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
What are the criteria used to check for duplication? For example, how would one know if the Maria of unspecified age from Brazil in row 5 is the same person as the 30-year old Maria from Brazil in row 6?
 
Upvote 0
Because there are only unique names. There's no other Maria, no other Robson and no other Carlos.
This may need some tweaking. For each unique name it retains the row with the most data associated with that name.
Code:
Sub RemoveNotSimpleDups()
'Names in column A are unique
Dim lR As Long, R As Range, i As Long, ct As Long, N() As Long, c As Range
'Sort names
Range("A2").Sort key1:=[A2], order1:=xlAscending, Header:=xlYes
Set R = Range("A1").CurrentRegion
Application.ScreenUpdating = False
For i = R.Rows.Count To 1 Step -1
    ct = Application.CountIf(R.Columns(1), R.Columns(1).Cells(i))
    If ct = 1 Then GoTo Nx
    If R.Columns(1).Cells(i) = R.Columns(1).Cells(i - 1) And _
        Application.CountA(R.Rows(i)) <= Application.CountA(R.Rows(i - 1)) Then
        R.Rows(i).Delete shift:=xlUp
    ElseIf R.Columns(1).Cells(i) = R.Columns(1).Cells(i - 1) And _
        Application.CountA(R.Rows(i)) > Application.CountA(R.Rows(i - 1)) Then
        R.Rows(i - 1).Delete shift:=xlUp
    End If
Nx:
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,205
Members
448,554
Latest member
Gleisner2

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