Removing and finding the Duplicates from arrays or excel sheet Rows entries

mandukes

Forum Rules
Joined
May 25, 2013
Messages
90
I need to remove duplicates from rows in excel sheet and also find the no of duplicates found in the current row.
12513
65465
69549

<tbody>
</tbody>

Output:

1 2 5 3
6 5 4
6 9 5 4

Can it be achieved using an arrays.

Code:
Dim ArrItem(100,50) as Integer 
ArrItems(1) = ArrItems(1,2,5,1,3)
ArrItems(2) = ArrItems(6,5,4,6,5)
ArrItems(3) = ArrItems(6,9,5,4,9)

Thanks and regards
~M
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
.. and also find the no of duplicates found in the current row.
1. Where do you want recorded the number of duplicates found in each row?

2. How do you count duplicates? That is, in the sample below, does this row have 2 duplicates (1 and 2) or does it have 3 duplicates (1, 2 and 1)?


Book1
ABCDEFG
21213214
Dupes


3. Do all rows have the same number of values to start with (5 in your example)?
 
Last edited:
Upvote 0
1. Where do you want recorded the number of duplicates found in each row?

Before Each row.

For example:
If 3 dupes found in the following.

DupesBCDEFG
2132121

<tbody>
</tbody>

The dupe should be removed from the Row i.e. 1,2,1
Giving the output as:

Output:
DupesBCDEFG
23132

<tbody>
</tbody>


2. How do you count duplicates? That is, in the sample below, does this row have 2 duplicates (1 and 2) or does it have 3 duplicates (1, 2 and 1)?

ABCDEFG
21213214

<tbody>
</tbody>


In your example given above.
It has 3 duplicates (1, 2 and 1)


3. Do all rows have the same number of values to start with (5 in your example)?

No, it can have more than 5 upto 100


Thanks :)
 
Last edited:
Upvote 0
Hi
Wasn't sure if you wanted to overwrite your data or copy the info to a new sheet.
This will write the unique values & the number of duplicates to a sheet called new.
You'll need to change the sheet name in red to match your data sheet.
Code:
Sub Del_DupesInRw()
' mandukes

    Dim Cl As Range
    Dim Rw As Long
    Dim Dupes As Long
    
Application.ScreenUpdating = False

    On Error Resume Next
    Sheets.Add.Name = "New"
    If Err.Number Then ActiveSheet.Delete
    On Error GoTo 0
    
    Sheets("[COLOR=#ff0000]overall[/COLOR]").Activate
    With CreateObject("scripting.dictionary")
        For Rw = 1 To Range("A" & Rows.Count).End(xlUp).Row
            For Each Cl In Range("A" & Rw, Cells(Rw, Columns.Count).End(xlToLeft))
                If Not .exists(Cl.Value) Then
                    .Add Cl.Value, Nothing
                Else
                    Dupes = Dupes + 1
                End If
            Next Cl
            Sheets("New").Rows(Rw).ClearContents
            Sheets("New").Range("A" & Rw) = Dupes
            Sheets("New").Range("B" & Rw).Resize(, .Count) = .keys
            Dupes = 0
            .removeall
        Next Rw
    End With
    
End Sub
 
Upvote 0
Thanks for the reply,
the code worked , The problem has been solved, I want to close this thread but couldn't find the option to do so..
 
Upvote 0
I want to close this thread but couldn't find the option to do so..
We don't have such an option in this forum because even though an OP (you) may be satisfied with one of the responses, it is not uncommon for somebody to come along later and offer an even better solution that you, or other readers, may want to use instead.
 
Upvote 0
Thanks for the reply,
the code worked , The problem has been solved, I want to close this thread but couldn't find the option to do so..

Glad to help &thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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