find duplicates in an array

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hello, I have a dynamic array 1 at (B1:F6845) and array 2 at (I6809:M6845), both are integers only; I would like to compare the array two against array one and highlight the duplicates in the array 2. and at the end of array two the amount of duplicates founded. like in N6846 the total of duplicates founded.


thanks.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
montecarlo2012,

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


Because of the number of rows, screenshots will not do.

So that we can get it right on the first try:

Can we see your workbook/worksheet with just the two ranges/arrays?

3. Are there columns to the immediate right of each array that I can use for a work area?

You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Last edited:
Upvote 0
Thanks, I am using excel 2010 on a pc. and after my first array there are two columns free G and H , any way I can move the second array anywhere if you want, the first one is too big to be moved. thanks. hiker95.
 
Upvote 0
montecarlo2012,

Thanks for the feedback. You are welcome.

there are two columns free G and H

That is great.

I can move the second array anywhere if you want, the first one is too big to be moved.

In order to assist you, and, so that we can get it right on the first try, can we see your workbook/worksheet with just the two ranges/arrays, in their correct/normal column position(s)?


You can upload your workbook to Box Net,

sensitive data changed

mark the workbook for sharing

and provide us with a link to your workbook.
 
Last edited:
Upvote 0
Sheet1

ABCDEFGHIJKLMNOP
682712/2/2014111142535
682812/3/20142583235
682912/4/20141253436 1253436duplicate found=4
683012/5/2014911121828 911121828
683112/6/20141015232931 1015232931
683212/7/2014111141621 111141621
683312/8/2014510142627 610142627
683412/9/201439141618 79141618
683512/10/201418103034 88103034
683612/11/2014510112036 910112036
683712/12/2014311182931 1011182931
683812/13/2014721232728
683912/14/2014414152526
684012/15/2014113182734
684112/16/201415222630
684212/17/2014314172326
684312/18/2014210162231
684412/19/201436212931
684512/20/20144672030
684612/21/2014710162324
6847

<colgroup><col style="width: 30px;"><col style="width: 114px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 64px;"><col style="width: 72px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 30px;"><col style="width: 113px;"><col style="width: 30px;"><col style="width: 75px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
montecarlo2012,

The following is based on the raw data that you have displayed.

Sample raw data:

Book1
ABCDEFGHIJKLMNOP
6826
682712/2/2014111142535
682812/3/20142583235
682912/4/201412534361253436duplicate found=
683012/5/2014911121828911121828
683112/6/201410152329311015232931
683212/7/2014111141621111141621
683312/8/2014510142627610142627
683412/9/20143914161879141618
683512/10/20141810303488103034
683612/11/2014510112036910112036
683712/12/20143111829311011182931
683812/13/2014721232728
683912/14/2014414152526
684012/15/2014113182734
684112/16/201415222630
684212/17/2014314172326
684312/18/2014210162231
684412/19/201436212931
684512/20/20144672030
684612/21/2014710162324
6847
Sheet1


After the macro:

Book1
ABCDEFGHIJKLMNOP
6826
682712/2/2014111142535
682812/3/20142583235
682912/4/201412534361253436duplicate found=4
683012/5/2014911121828911121828
683112/6/201410152329311015232931
683212/7/2014111141621111141621
683312/8/2014510142627610142627
683412/9/20143914161879141618
683512/10/20141810303488103034
683612/11/2014510112036910112036
683712/12/20143111829311011182931
683812/13/2014721232728
683912/14/2014414152526
684012/15/2014113182734
684112/16/201415222630
684212/17/2014314172326
684312/18/2014210162231
684412/19/201436212931
684512/20/20144672030
684612/21/2014710162324
6847
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub FindDuplicates()
' hiker95, 12/22/2014, ME825417
Dim lrb As Long, lri As Long
Dim c As Range, g As Range, n As Long
Application.ScreenUpdating = False
lrb = Cells(Rows.Count, "B").End(xlUp).Row
lri = Cells(Rows.Count, "I").End(xlUp).Row
With Range("G6827:G" & lrb)
  .Formula = "=B6827&C6827&D6827&E6827&F6827"
  .Value = .Value
End With
With Range("H6829:H" & lri)
  .Formula = "=I6829&J6829&K6829&L6829&M6829"
  .Value = .Value
End With
For Each c In Range("H6829:H" & lri)
  Set g = Range("G6827:G" & lrb).Find(c.Value, LookAt:=xlWhole)
  If Not g Is Nothing Then
    n = n + 1
    Range("I" & c.Row).Resize(, 5).Interior.Color = vbYellow
  End If
Next c
With Range("O6829")
  .Value = n
  .Interior.Color = vbYellow
End With
Range("G6827:G" & lrb).ClearContents
Range("H6829:H" & lri).ClearContents
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the FindDuplicates macro.
 
Last edited by a moderator:
Upvote 0
thank you hiker95
work perfect, I would like to find somebody like you, to get tutorials.
MARRY CHRISTMAS
 
Upvote 0
Sorry about this, but I forgot the main point of this, work in that range of the example, but I really tried is to compare array1 (B2:to the end) against array2 , this second array is dynamic also, could be (I2: to the end) or could be just small as the example. in the same spat ofcourse. thanks.
 
Upvote 0
work perfect,..
Are you sure?
With sample data as laid out in post #6, add the following values in row 6838 then run the code again

Col: Value
I: 11
J: 1
K: 14
L: 16
M: 21


Sorry about this, but I forgot the main point of this, work in that range of the example, but I really tried is to compare array1 (B2:to the end) against array2 , this second array is dynamic also, could be (I2: to the end) or could be just small as the example. in the same spat ofcourse. thanks.
Your earlier post seemed to indicate that the second array could go anywhere, and this one indicates data starting in row 2 so I'm assuming headings in row 1, at least in columns I:M

If that is the case, with the second array at the top of columns I:M as shown below, try this macro instead. The count of duplicate rows is shown in cell O1 but that could be anywhere.

Rich (BB code):
Sub Find_Dupe_Rows()
  Dim lr As Long
  
  Application.ScreenUpdating = False
  lr = Range("B" & Rows.Count).End(xlUp).Row
  With Range("I1", Range("M" & Rows.Count).End(xlUp))
    .Cells(3, -1).Formula = Replace("=COUNTIFS(B$2:B$#,I2,C$2:C$#,J2,D$2:D$#,K2,E$2:E$#,L2,F$2:F$#,M2)", "#", lr)
    .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=.Cells(2, -1).Resize(2), Unique:=False
    .SpecialCells(xlVisible).Interior.ColorIndex = 27
    .Rows(1).Interior.ColorIndex = 0
    .Cells(1, 7).Value = .Columns(1).SpecialCells(xlVisible).Count - 1
    .Parent.ShowAllData
    .Cells(3, -1).ClearContents
  End With
  Application.ScreenUpdating = True
End Sub

Excel Workbook
BCDEFGHIJKLMNO
1Col 2Col 3Col 4Col 5Col 6Col 9Col 10Col 11Col 12Col 13
21111425351253436
32583235911121828
412534361015232931
5911121828111141621
61015232931610142627
711114162179141618
851014262788103034
939141618910112036
10181030341011182931
11510112036111141621
123111829314672030
13721232728
14414152526
15113182734
1615222630
17314172326
18210162231
1936212931
204672030
21710162324
22
Before Code



Excel Workbook
BCDEFGHIJKLMNO
1Col 2Col 3Col 4Col 5Col 6Col 9Col 10Col 11Col 12Col 135
21111425351253436
32583235911121828
412534361015232931
5911121828111141621
61015232931610142627
711114162179141618
851014262788103034
939141618910112036
10181030341011182931
11510112036111141621
123111829314672030
13721232728
14414152526
15113182734
1615222630
17314172326
18210162231
1936212931
204672030
21710162324
22
After Code
 
Upvote 0
montecarlo2012,

thank you hiker95
work perfect, MARRY CHRISTMAS

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.

And, Happy Holidays, Merry Christmas, and, a Happy New Year.

I would like to find somebody like you, to get tutorials.

See if something, in the below link, of my most up to date list will help you:

Training / Books / Sites as of 11/22/2014

http://www.mrexcel.com/forum/genera...ns/820920-how-we-learn-excel.html#post4006402
 
Upvote 0

Forum statistics

Threads
1,221,501
Messages
6,160,175
Members
451,629
Latest member
MNexcelguy19

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