Highlighting duplicates in a worksheet column

EDUCATED MONKEY

Board Regular
Joined
Jul 17, 2011
Messages
218
Hi I thought posting this would stop other wasting time!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
The set up is office 2007 windows XP professional IE8<o:p></o:p>
Object of the exercise was to find duplicated data in a worksheet column <o:p></o:p>
So I headed of to the data tools and selected remove duplicates now here is the warning select the data NOT the column, if you select the column you will get random answers depending upon your last entry in that column<o:p></o:p>
Having got this to work I needed a method to tell me where the duplicates are and not just delete them so I opted for the conditional formatting, which despite leaving the system running for two days produced nothing just hangs then the only way back is control halt delete!<o:p></o:p>
So I devised a plan, first sort the data so that duplicated data would end up on consecutive rows, the I could simply compare the values and were they matched row after row then I changed the cell colour and I had the answer I was seeking two days earlier within a minuet. <o:p></o:p>
The code below is how I achieved this; I am not saying this is the best way just one way to get the job done<o:p></o:p>
The hope is that you will not waste as much time over it as I did trying to get the conditional formatting to work <o:p></o:p>
Code:
Sub COlourDups()
'
' COlourDups Macro
'
' Keyboard Shortcut: Ctrl+c
'
Dim Mystring1 As String
Dim Mystring2 As String
Dim n As Long
'
ActiveWorkbook.Sheets("ISBN DATA BASE1").Activate

For n = 1 To 87674 'max number of rows to test
 Mystring1 = Worksheets("ISBN DATA BASE1").Cells(n, 3).Value ' column C
 
 Mystring2 = Worksheets("ISBN DATA BASE1").Cells(n + 1, 3).Value ' column C
  
 If Mystring1 = Mystring2 Then
 
 Worksheets("ISBN DATA BASE1").Cells(n, 3).Interior.Color = 16751103
 Worksheets("ISBN DATA BASE1").Cells(n + 1, 3).Interior.Color = 16751103
  
 End If
 
 Next n

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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