Making Rule work on Select Columns

Hey I have this rule which highlights duplicates in a row in different colors so if you have a row that is

1
1
1
2
2
3
1
3

All the one's will be blue 2's red and 1's white. Currently the rule below only works on column A. All my columns have headers, and I need it to instead of working on column A work on the columns with header names I choose.
Anyone have any idea how this can be accomplished??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, Dn As Range
Dim K
Dim col
Dim c As Integer
If Target.Column = 1 Then
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not .Exists(Dn.Value) Then
.Add Dn.Value, Dn
Else
Set .Item(Dn.Value) = Union(.Item(Dn.Value), Dn)
End If
Next
col = Array(3, 50, 6, 7, 8, 34, 35, 38, 39, 50, 45, 46)
For Each K In .keys
If .Item(K).Count > 1 Then
c = IIf(c = 12, 0, c)
.Item(K).Interior.ColorIndex = col(c)
c = c + 1
End If
Next K
End With
End If
End Sub

Nick's picture

take a step back... what are

take a step back...
what are you actually trying to achieve here ?

you have some dupes and you want to group them...
- surely the best way to do that is to sort the data.. you can then use conditional formatting to colour the rows where the value changes... No VBA needed.

Not at all, conditional

Not at all, conditional formatting does not accomplish what I need.

lets say my data is
1
1
1
1
2
2
2
3
3
3
Conditional formatting will just highlight everything in a certain color. I need each group to be a separate color.

Anyone have an idea?

Anyone have an idea?

Nick's picture

I'd like to get to the root

I'd like to get to the root of your request.. why do you need each group to be a different colour ?

... and if this is a must, surely you only need to create a rule per colour, and you're done..

I have to send reports which

I have to send reports which show connections between various criteria for example address, city, zip , ip and so forth.

The reports may include 100 rows. I need for each matching zip code to be highlighted a certain color, for each group of similar ip's to be colored and so forth.

I just need to be able to tell the rule to work on a column of a selected name for example apply this rule to columns with headers IP Address and Zipcode

Got the help I need, Thank

Got the help I need, Thank you!