in eccel 2003- 3 duplicate values in column to be coloured

rupashree

New Member
Joined
Jun 16, 2011
Messages
21
in a sorted column containing 3 sequential duplicate values, the cells need to be coloured.others should be left without colouring.please provide a macro.the cells much be coloured only that contains 3 duplicate values

<table width="100" border="0" cellpadding="0" cellspacing="0"><col style="width: 75pt;" width="100"> <tbody><tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt; width: 75pt;" width="100" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl24" style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl24" style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl24" style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt;" height="17">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt;" height="17">
</td> </tr> </tbody></table>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the board.

What column is your data in?

What happens if you have values
A1: 1
A2: 1
A3: 1
A4: 1

Should A1:A3 be coloured and not A4? Or should A1:A3 be coloured and then A2:A4 be coloured?

Try:
Rich (BB code):
Sub FindLastColumn()
 
Dim i As Long, j As Long
 
Application.ScreenUpdating = False
 
'With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
'    .Sort key1:=Range("A1"), order1:=xlAscending, header:=xlGuess
'End With
 
i = 1
Do While Not IsEmpty(Range("A" & i))
    If Range("A" & i) = Range("A" & i + 1) And Range("A" & i) = Range("A" & i + 2) Then
        Range("A" & i & ":A" & i + 2).Interior.ColorIndex = 3
    End if        
    i = i + 1
Loop
 
Application.ScreenUpdating = True
 
End Sub
If you remove the first character ' from lines 4, 5 and 6 above, it will sort the column in ascending order first
 
Upvote 0
Change my code to:
Rich (BB code):
Sub FindLastColumn()
 
Dim i As Long, j As Long
 
Application.ScreenUpdating = False
 
'With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
' .Sort key1:=Range("A1"), order1:=xlAscending, header:=xlGuess
'End With
 
i = 1
Do While Not IsEmpty(Range("A" & i))
  If Range("A" & i) = Range("A" & i + 1) And Range("A" & i) = Range("A" & i + 2) Then
    Range("A" & i & ":A" & i + 2).Interior.ColorIndex = 3
    i = i + 3
  Else
    i = i + 1
  End if 
Loop
 
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
What column is your data in? I have my test data in column A and it works fine, it colours consequtive cells of three the colour red if the values are the same.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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