(VBA) Search duplicates in one columns, determine it by another

sh1ne

New Member
Joined
Jul 3, 2017
Messages
33
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys,

I want to describe my problem as much as I can. My target is to create macro which will highlight the duplicated rows searching in column B, but all is determinated by Column A. Values in column B can be same and not highlighted if values in column A are different. CountIf is good for highlight cells within range for only duplicates, what about conditional highlight? InStr would be good, but how I can store informations about which cells are need to be compared(there can be more than 1000 rows)

To make it clear, below is example:

colA____colB
ABC____XYZ
ABC____YZX
BCA____XYZ
BCA____ZXY
CBA____XYZ
ABC____XYZ

As you see, there are many XYZ in column B, but everything is ok if colA is different. Any ideas how macro should look like?
 
I have no experience with Mac - see if this works

Code:
Sub HihglightDupes()
    Dim lastRow As Long, rCell As Range
    Dim lCounter As Long
    
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    For Each rCell In Range("A2:A" & lastRow)
        lCounter = _
            Evaluate(Replace("=COUNTIFS(A2:A@,""" & rCell.Value & """,B2:B@,""" & rCell.Offset(, 1) & """)", "@", lastRow))
        If lCounter > 1 Then rCell.Resize(, 2).Font.Color = vbRed
    Next rCell
End Sub

M.
Thanks a lot mate, with little changes it's working properly like I wanted.
 
Upvote 0

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).

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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