How can I create a macro in MS excel to find duplicates in a spreadsheet and highlight it
+2
A:
You don't need a VBA macro. You can just use conditional formatting. Microsoft explain how to do exactly what you seem to need here:
http://office.microsoft.com/en-us/excel/HA011366161033.aspx
If you really need a macro, the easiest way would be to record the steps described above, then edit as needed.
Paul Rayner
2010-01-29 15:09:27
A:
Maybe this snippet is useful:
Public Sub MarkDuplicates()
Dim iWarnColor As Integer
Dim rng As Range
Dim rngCell As Variant
Set rng = Range("A1:A200") ' area to check '
iWarnColor = xlThemeColorAccent2
For Each rngCell In rng.Cells
vVal = rngCell.Text
If (WorksheetFunction.CountIf(rng, vVal) = 1) Then
rngCell.Interior.Pattern = xlNone
Else
rngCell.Interior.ColorIndex = iWarnColor
End If
Next rngCell
End Sub
Karsten W.
2010-01-29 21:42:01