Automatically color rows based on matching values (with separate colors for each match)

FrumpyJones

New Member
Joined
Feb 11, 2008
Messages
28
Hi Everyone,

I am getting an output that looks like this:

8/21/2017 1131312865
8/21/2017 1131312865
8/7/2017 1131221294
8/7/2017 1131221294
8/7/2017 1131221294
8/7/2017 1131221294
8/7/2017 1131221294
3/28/2017 1160019485
3/28/2017 1160019485
3/28/2017 1160019485
2/21/2017 1130300368
2/21/2017 1130300368
2/21/2017 1130300368​

This output could have 1000 rows or greater.

What I ultimately want to do is have it color the entire row based on matching numbers in column b, with a cycling color scheme (Gray/white/gray/white)

What I could live with is it just cycle color scheme the individual duplicate values.

Here's what I mean:

8/21/2017 1131312865
8/21/2017 1131312865

8/7/2017 1131221294
8/7/2017 1131221294
8/7/2017 1131221294
8/7/2017 1131221294
8/7/2017 1131221294

3/28/2017 1160019485
3/28/2017 1160019485
3/28/2017 1160019485

2/21/2017 1130300368
2/21/2017 1130300368
2/21/2017 1130300368

Is this doable?
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Here's a simple loop that should do the trick:

Code:
Option Explicit
Const lColor1 As Long = 8421504   'grey
Const lColor2 As Long = 12611584  'blue

Function NextColor(ByVal lColor As Long) As Long
If lColor = lColor2 Then
    NextColor = lColor1
Else
    NextColor = lColor2
End If
End Function

Sub Highlights()
Dim rng As Range
Dim cel As Range
Dim lCol As Long
Dim v As Variant

Set rng = Range([B1], Cells(Rows.Count, 2).End(xlUp))
For Each cel In rng.Cells
    If Not cel = v Then lCol = NextColor(lCol)
    cel.EntireRow.Font.Color = lCol
    v = cel
Next cel
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

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