Identify duplicates

jsiason

Board Regular
Joined
Nov 9, 2005
Messages
72
Needing help..

In column F, id like to make a list of duplicate items found in columns C vs. D (not "per row" qualification). And in column G, id like to consolidate items in C and D but eliminating any duplicates.

Thank you!
 

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.
jsiason.

i think this should work for you. let me know if you have any questions.

ben.
Code:
Sub HandlingDuplicates()

Dim List1 As Range, List2 As Range
Dim LoopList As Range, SearchList As Range
Dim DuplicateList As Range, UniqueList As Range
Dim StartRow As Long

StartRow = 1 '<--Change this to beginning of your lists

Set List1 = Range(Cells(StartRow, "C"), Cells(Rows.Count, "C").End(xlUp))
Set List2 = Range(Cells(StartRow, "D"), Cells(Rows.Count, "D").End(xlUp))
Set DuplicateList = Range("F1")
Set UniqueList = Range("G1")

DuplicateList.Value = "DUPLICATES"
UniqueList.Value = "UNIQUE"

If List1.Rows.Count > List2.Rows.Count Then
    Set LoopList = List2
    Set SearchList = List1
Else
    Set LoopList = List1
    Set SearchList = List2
End If

Application.ScreenUpdating = False

For Each c In LoopList.Cells
    If Application.WorksheetFunction.CountIf(SearchList, c.Value) >= 1 Then
        Set DuplicateList = DuplicateList.Offset(1, 0).Resize(1, 1)
        DuplicateList = c.Value
        'Set DuplicateList = DuplicateList.Resize(DuplicateList.Rows.Count + 1, 1)
    Else
       Set UniqueList = UniqueList.Offset(1, 0).Resize(1, 1)
       UniqueList = c.Value
    End If
Next c

Application.ScreenUpdating = True

End Sub
 
Upvote 0
hi ben, can this be done using function (and not using macros)?

easiest steps that will produce this output...

Also, in column G, i meant list unique values including those that appear in C and D, just that they will appear only once as one item in column G.
 
Upvote 0
jsiason said:
hi ben, can this be done using function (and not using macros)?

easiest steps that will produce this output...

Also, in column G, i meant list unique values including those that appear in C and D, just that they will appear only once as one item in column G.

Care to post a 10-row sample along with the expected output?
 
Upvote 0
js.

is this what you mean?

ben.
(ignore &nsdf or whateveR)
book1
CDEFG
1LIST1LIST2COMBINEDUNIQUE
2aaaa
3bbab
4ccbc
5dxbd
6eyce
7fzcf
8gzdg
9ex
10fy
11gz
12x
13y
14z
15z
Sheet1
 
Upvote 0
C D E F G
a b e a
c d a b
e e i c
f g d
h a e
b i f
g
h
i


i hope i didnt confuse you.

If this can be done using a series of functions and without using macros, that will be great, ben.[/img]
 
Upvote 0
sample.jpg


how bout this?[/list]
 
Upvote 0
If you download and install the free morefunc.xll add-in...
Book7
CDEFGH
1039
2List-1List-2IdxCommonListMerged Distinct List
3ab1aa
4cd eb
5ee2bc
6fg  d
7ha e
8bi3f
9g
10h
11i
12 
Sheet1


E1 must house a 0.

E3, copied down:

=IF(C3<>"",IF(ISNA(MATCH(C3,$C$2:C2,0))*ISNUMBER(MATCH(C3,$D$3:$D$8,0)),LOOKUP(9.99999999999999E+307,$E$1:E2)+1,""),"")

G1:

=LOOKUP(9.99999999999999E+307,E3:E8)

G3, copied down:

=IF(ROW()-ROW(G$3)+1<=$G$1,LOOKUP(ROW()-ROW(G$3)+1,$E$3:$E$8,$C$3:$C$8),"")

H1:

=COUNTDIFF(C3:D8)

Uses a function from morefunc.

H3, copied down:

=IF(ROW()-ROW($H$3)+1<=$H$1,INDEX(UNIQUEVALUES($C$3:$D$8,1),ROW()-ROW($H$3)+1),"")

Also uses a function from morefunc.
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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