You are here:

Excel/Finding duplicate value

Advertisement


Question
Hello Tom,
Hope u are fine..
I have a data with number and text in column like below,

14
16
18
75
rak
gho
14
28
56
gho
123
rak
75
34

i want to find out the duplicate value within that column,
which i can find from conditional formatting tool by highlighting duplicate values option.

but it shows all the duplicate value in one color, such as after click of highlight duplicate it's shows all in pink.

in above case my duplicate values are 14,75,rak,gho and system showing all in pink color.

i want them in different color (e.g 14/14 should have green, 75/75 in red, rak/rak in yellow etc...

hope you understand what i mean to say.
i want duplicate values should be in different set of color , so that i can identify that how many set of duplicate values.
present in data.

Thanks
Rakesh

Answer
Rakesh,

select your data and run this routine.  i can only take values 1 to 56.  I started it at 33 since those colors are lighter.  However, if you have a lot of differenct duplicate values, it will loop around and may color a cell with a dark color.

Sub abc()
Dim r As Range, cell As Range
Dim r1 As Range, cell1 As Range
Dim i As Long
i = 33
Set r = Selection
r.Interior.ColorIndex = xlNone
For Each cell In Selection
 If cell.Row < r(r.Count).Row Then
   Set r1 = Range(cell.Offset(1, 0), r(r.Count))
   If Application.CountIf(r1, cell) > 0 Then
     For Each cell1 In r1
       If cell.Value = cell1.Value Then
         cell.Interior.ColorIndex = i
         cell1.Interior.ColorIndex = i
       End If
     Next
     i = i + 1
     if i > 56 then i = 3
   End If
 End If
Next
End Sub

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.