Coloring the duplicates with VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would absolutely appreciate any help on the following

How can I color duplicates rows with random colors.
Duplicate are found by searching col A only. e.g a random color (e.g green)
is applied to all occurrence of word "Jane" in col A, then another random
color (e.g) red is applied to all occurrence of word "Jill" and so on.

The idea is visually to see duplicates.
Is this possible ?

Thanks a million for your help

I use XL 2002 on Win 2K
 
Conditional formatting will identify duplicates, but if want random colours
you will need VBA.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bobby,

This is what I read that you want, but I have to say, I don't like it

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim rng As Range

Set rng = Range("A1:A100")
Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, rng) Is Nothing Then
With Target
For Each cell In rng
If WorksheetFunction.CountIf(rng, cell) > 1 Then
cell.Interior.ColorIndex = Int(Rnd(1) * 56) + 1
End If
Next cell
End With
End If
sub_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top