Checking values in one column

Konrado

New Member
Joined
Jun 17, 2014
Messages
34
Hi, I want to write a code which checks values in one column. If they're equal, they have yellow color. Unfortunately, my code doesn't work. If you could help me, I will be very happy. My code below.


Sub Compare()
Dim sh As Range
Dim i, j As Long
For Each sh In Range("A1:A17")
For i = 1 To 17
For j = 1 To 17
If sh(i, "A") = sh(j, "A") Then
sh(i, "A").Interior.Color = vbYellow
sh(j, "A").Interior.Color = vbYellow
End If
Next j
Next i
Next sh
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Am No VBA expert but does this work?

Code:
Sub Compare()
Dim i, j As Long
For i = 1 To 16
For j = i+1 To 17
If Cells(i, 1) = Cells(j, 1) Then
Cells(i, 1).Interior.Color = vbYellow
Cells(j, 1).Interior.Color = vbYellow
End If
Next j
Next i
End Sub

Note removal of sh loop
There's prob a better way to do it
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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