Color code duplicates with a twist

most

Board Regular
Joined
Feb 22, 2011
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Mobile
I know color code duplicates is a very common issue here on the internet, but I can't find any solution which is similar to my needs.

Based on the value in column A("My data") I want to color code the whole row where the value is the same.
I.e. row 1 and 2 has the same value and should be colored to grey. Row 3, 4 and 5 has the same value and should be colored to a another color and so on.

My data(entire row color)
10Grey
10Grey
20Dark grey
20Dark grey
20Dark grey
30Grey
30Grey
40Dark grey
40Dark grey

<tbody>
</tbody>

This is my code for the moment, but it doesn't work. The second if statement is major wrong.
Code:
LastRow = Cells(Rows.count, 1).End(xlUp).rowrowcolor = 225


For Each c In Range("A2:A" & LastRow)
 If c.Offset(1, 0).Value = c.Value Then
     Rows(c.row).EntireRow.Interior.Color = RGB(205, rowcolor, 205)
     Rows(c.row + 1).EntireRow.Interior.Color = RGB(205, rowcolor, 205)
 End If
   If rowcolor = 225 Then
     rowcolor = 255
      Else
     rowcolor = 225
   End If
Next c
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
Code:
   lastrow = Cells(Rows.Count, 1).End(xlUp).Row
   rowcolor = 225
   
   For Each c In Range("A2:A" & lastrow)
      If c.Offset(1, 0).Value = c.Value Then
         Rows(c.Row).Resize(2).Interior.Color = RGB(205, rowcolor, 205)
      Else
         rowcolor = IIf(rowcolor = 225, 255, 225)
      End If
   Next c
 
Upvote 0
Why are you so smart? =) Thanks!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,867
Members
449,053
Latest member
Mesh

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