Change some font colour from black to white

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

The code below do highlight duplicates in various colours as shown below</SPAN></SPAN>
Code:
Sub Find_Duplicate_Entry()
    Dim Cel As Variant
    Dim myrng As Range
    Dim clr As Long
    Set myrng = Range("D6:D" & Range("D65536").End(xlUp).Row)
    myrng.Interior.ColorIndex = xlNone
    myrng.Font.ColorIndex = 1
    clr = 3
    For Each Cel In myrng
        If Application.WorksheetFunction.CountIf(myrng, Cel) > 1 Then
            If WorksheetFunction.CountIf(Range("D6:D" & Cel.Row), Cel) = 1 Then
                Cel.Interior.ColorIndex = clr
                If clr = 6 Then clr = 3
                clr = clr + 1
            Else
                Cel.Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(Cel.Value, myrng, False), 1).Interior.ColorIndex
            End If
        End If
    Next
End Sub

Book1
CDE
1
2
3
4
5
60
70
80
90
100
110
120
131
141
151
161
172
182
193
204
215
225
236
247
257
267
277
287
297
3022
3122
3222
3323
3424
3525
3626
3726
38178
39179
40179
41180
42180
43180
44180
45180
46183
47183
48183
49183
50183
51184
52184
53184
54184
55184
56184
57184
58245
59245
60245
61246
62246
63246
64247
65247
66247
67247
68247
69248
70248
71248
72248
73248
74249
75249
76249
77249
78249
79249
80474
81474
82474
83474
84525
85525
86525
87525
88525
89570
90571
91571
92572
93573
94573
95
96
Sheet1


I would like to get change font colour white in the Red & Blue background as shown below. Please need help someone can modified the above code or make a new one</SPAN></SPAN>

Like this</SPAN>

Book1
CDE
1
2
3
4
5
60
70
80
90
100
110
120
131
141
151
161
172
182
193
204
215
225
236
247
257
267
277
287
297
3022
3122
3222
3323
3424
3525
3626
3726
38178
39179
40179
41180
42180
43180
44180
45180
46183
47183
48183
49183
50183
51184
52184
53184
54184
55184
56184
57184
58245
59245
60245
61246
62246
63246
64247
65247
66247
67247
68247
69248
70248
71248
72248
73248
74249
75249
76249
77249
78249
79249
80474
81474
82474
83474
84525
85525
86525
87525
88525
89570
90571
91571
92572
93573
94573
95
96
Sheet1-1



Thank you all</SPAN></SPAN>
Excel 2000</SPAN></SPAN>
Regards,</SPAN>
Moti</SPAN>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The code below do highlight duplicates in various colours as shown below
Rich (BB code):
Sub Find_Duplicate_Entry()
    Dim Cel As Variant
    Dim myrng As Range
    Dim clr As Long
    Set myrng = Range("D6:D" & Range("D65536").End(xlUp).Row)
    myrng.Interior.ColorIndex = xlNone
    myrng.Font.ColorIndex = 1
    clr = 3
    For Each Cel In myrng
        If Application.WorksheetFunction.CountIf(myrng, Cel) > 1 Then
            If WorksheetFunction.CountIf(Range("D6:D" & Cel.Row), Cel) = 1 Then
                Cel.Interior.ColorIndex = clr
                If clr = 6 Then clr = 3
                clr = clr + 1
            Else
                Cel.Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(Cel.Value, myrng, False), 1).Interior.ColorIndex
            End If
        End If
        Cel.Font.Color = -vbWhite * (77 * (Cel.Interior.Color Mod &H100) + 151 * ((Cel.Interior.Color \ &H100) Mod &H100) + 28 * ((Cel.Interior.Color \ &H10000) Mod &H100) < 32640)
    Next
End Sub
Add the line of code I show in red above (it will automatically choose the correct black or white font color to use no matter what background colors you use to color your cells).
 
Last edited:
Upvote 0
Add the line of code I show in red above (it will automatically choose the correct black or white font color to use no matter what background colors you use to color your cells).
Thank you so much Rick, adding a just one line you made my life easer. It has been great help for me :beerchug:</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti :)
</SPAN></SPAN>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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