title: RemoveDuplicates is not working as expected
body: <p>I have a large data set that is exported from a website.  I use a macro in my main ‘filter’ workbook to find the file and copy the data from Sheet1 of the exported file into Sheet1 of the filter workbook.  </p>
  
  <p>Once the data is copied into Sheet1 of the filter workbook, I use VBA to copy columns A/B/D/F/H/Z/AA/etc from Sheet 1 of the filter workbook into Sheet2 of the filter workbook AND also at the same time, I use this code here to attempt to delete any duplicate rows:</p>
  
  <p>Worksheets("Sheet2").Range("A:DZ").RemoveDuplicates Columns:=15, Header:=xlYes   </p>
  
  <p>I am finding though that the RemoveDuplicates is not working as expected.  </p>
  
  <p>As an example, Sheet1 in the filter workbook (and export workbook) has 3344 rows.  When I manually filter using conditional formatting to highlight duplicates, I can find 314 rows listed as duplicates (meaning 157 genuine rows of actual data and 157 rows which are duplicates of that actual data.  I haven’t found any examples of duplicates existing more than one time each).  So on Sheet2 I was expecting to see 3344 – 157 = 3157 Rows of real data.  I don’t see that, or even 3030 rows (3344-314).  Instead, I am getting 1897 rows paste into Sheet2, which is a difference of 1447 rows (1290 less rows than expected). </p>
  
  <p>On top of that, I am manually checking the data to see what is up by using Control-F in the column and am finding that in some instances that both of the two duplicated items are missing from Sheet2 (versus it just deleting the one duplicate row).  </p>
  
  <p>The duplicate data is not on sequential rows and is scattered throughout the column in Sheet2.  But when I sort it before I attempt to DeleteDuplicates, it does not seem to impact its accuracy or make it right. 
  I have also tried using the DeleteDuplicates in different locations of the code / at different times but the results are always off by the same amount (1447 missing rows instead of 157 missing rows).  </p>
  
  <p>I found only a few articles on this site, this one was the closest but not quiet my issue: <a href="https://stackoverflow.com/questions/23820173/delete-rows-with-duplicate-data-vba/23820451#23820451">Delete Rows With Duplicate Data VBA</a></p>
  
  <p>And other help sites/forums mention there was some bug with office 2007 that prevents this from working (am using 2013).  </p>
  
  <p>Does anyone know where I can find a work around, or if one exists - or if this is still a real bug or just a problem with the code line I have above. </p>
  
  <pre><code>Adding bits of code I use in this example in case it is something within     these that is causing the problem…
  Part of the copy code: 
  wsFromSheet.Cells.Copy
  wsToFile.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
  Application.CutCopyMode = False
  wbFromFile.Close True
  
  Part of the ‘paste column code’:
  Sheets("Sheet2").Rows(1 &amp; ":" &amp;     Sheets("Sheet2").Columns.Count).ClearContents 'Clear from row 1 down
  LastRowFromSiteTracker = xSht.Cells.SpecialCells(xlCellTypeLastCell).Row      'original report has 128 columns
  xSht.Range("B1:B" &amp; LastRowFromSiteTracker).Copy ySht.Cells(Rows.Count,    "A").End(xlUp)      'customer name
  ‘repeat a bunch of times, then…
  Application.CutCopyMode = False  'do I need this line?
  Worksheets("Sheet2").Range("A:DZ").RemoveDuplicates Columns:=15,   Header:=xlYes 
  End Sub
  
  
  Example/sample of data:
  
  Row Source Data Expected Data   Actual Data
  1   1000474608  1000474608  1000474608 (Dup missing from sheet2)
  2   1000474608  1000487672  1000487672
  3   1000487672  1000487674  1000487674
  4   1000487674  1000487676  1000487676 (missing from sheet2, wasn’t a dup)
  5   1000487676  1000487678  1000487678
  6   1000487678  1000487680  1000487680
  7   1000487680  1000487682  1000487682 (Dup missing from sheet2)
  8   1000487682  1000520278  1000520278
  9   1000487682  1000520280  1000520280
  10  1000520278  1000520282  1000520282 (Is there)
  11  1000520280  1000520286  1000520286
  12  1000520282  1000520336  1000520336 (Is there)
  13  1000520282  1000520338  1000520338
  14  1000520286  1000520392  1000520392
  15  1000520286  1000520394  1000520394
  16  1000520336  1000530333  1000530333
  17  1000520338      
  18  1000520392      
  19  1000520394      
  20  1000530333      
  </code></pre>
  
  <p><strong><em>EDIT:  EDIT:  EDIT:</em></strong>
  So I've tried to do some more manual testing, and tried two separate things with the same set of data, getting two different results.  I used the Conditional Formatting - Highlight Duplicates from the main Home ribbon and the Remove Duplicates from the Data ribbon. </p>
  
  <p>The Remove Duplicates button finds and removed 163 items in Column P and leaves 3181 rows.  </p>
  
  <p>However, when I use the Highlight Duplicates conditional format finds 314 items that are duplicated within Column P, leaving 3030 non duplicates. </p>
  
  <p>It does not make sense that these two numbers do not match.  I thought it has something to do with the duplicates themselves - as most duplicated items have only one dup of itself (123123 shows up in two rows) but then just a small handful of rows are duplicated multiple times (234234 shows up in 4 or 6 columns).  </p>
  
  <p>So instead of using the manual way, I used the suggestions I've found online, and both of these also provide differing results when run:</p>
  
  <pre><code>3344 Base records
  
  1897 left after scrub of duplicates  (1446 removed)
  
  Dim tmpAddress As String
  tmpAddress = "A2:BZ" &amp; Worksheets("ColScrub").UsedRange.Rows.Count 
  Worksheets("ColScrub").Range(tmpAddress).RemoveDuplicates Columns:=15, Header:=xlNo
  
  
  3181 left after scrub of duplicates (162 removed)
  
  Cells.Select
  ActiveSheet.Range("$A$1:$EI$3345").RemoveDuplicates Columns:=31, Header:=xlYes
  </code></pre>