VBA macro to Find and Highlight duplicate/match

Alphix

New Member
Joined
Sep 29, 2016
Messages
22
Hi I am stuck on how to accomplish the following:
I need a VBA macro to Find and Highlight duplicate/match within a range of part numbers and to find an highlight a match within 3 columns.
See image.

Your help is greatly appreciated.
 

Attachments

  • Find Matches.png
    Find Matches.png
    70.8 KB · Views: 36

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi, can you please share the data using XL2BB.

It would help to copy the data in my excel.

Thanks,
Saurabh
 
Upvote 0
Hi Saurabh, below is the data.

Check for Dup.xlsx
ABCDE
1
2Check For DuplicateCheck 1Check 2Check 3
3A03B-0824-K202MAKINO Z-AXIS WIPER #Y000Z2010049, OLD MY000Z2010049 MAKINO
4A03B-0824-K203SEALING DISK CDER32040M ADB CDER32040M ERICKSON KENNAMETAL
5A06B-1468-B133#0R21SEAL DISK CDER32100M ADB CDER32100M KENNAMETAL
6A06B-2227-B20015IP TORX TORQUE DRIVER,300 TX15 3,0Nm 5027935001 A60L-0001-0183#75ASWERA, MOTION # 12702X00045
7A06B-2247-B100SPRING-GUIDE-ATC ARM - 16M60A702 MA0116M60A702 MAKINO 11
8A06B-2247-B400SPRING Z291A3404015 SPINDLE COOLANT Z291A3404015 MAKINO 11
9A06B-6200-C601PALLET STOP #M0302700 M0302700 MAKINO
10A06B-6200-C603SCREW CLAMP STCM35-T15 KENNAMETAL/ORDER STCM35-T15 KENNAMETAL
11A06B-6200-C604SCREW MS1157PKG KENNAMETAL 10 PCS=1PACK MS1157 (1) = PKG OF 10 PRICE $28.79 PAK KENNAMETAL ORDER 1 = 1 PKG OF 10 SCREWS
12A06B-6200-C607SCREW M6 MS-965 MS965 A03B-0824-K202 KENNAMETAL
13A06B-6200-C609SCREW M6 #MS966 KENNAMETAL ADB MS966 KENNAMETAL
14A06B-6200-C610INSERT SCREW MS-1160 ADB MS-1160 KENNAMETAL
15A06B-6200-H026LOCK SCREW M6 F.P.S.S.S. ADB M6X6FPSSS ADAPTIVE TECH
16A06B-6220-H015#H600BAR CODE SCANNER COMPLETE (MFG. P/N KK370-SR1211100US SEND OUT FOR REPAIR SYMBOL-OBSOLETE-NEED SUGGEST REPLACMENT
17A06B-6240-H20812X1/2X18T HIGH SPEED HACKSAW BLD 218HE 218HE ITEM# 03099983 AMERICAN S MOTION
18A06B-6240-H209792541-7 MAKITA SAW BLADES (PK/5) 792541-7 MAKITA A98L00310028
19A20B-2004-0691
20A20B-2101-0840Compare Column A for duplicate in D,E,F Columns
21A20B-2102-0672First Compare as an exact matchHighlight Match
22A20B-2102-0681Second compare without hyphensHighlight Match
23A60L-0001-0183#100ASThird compare without spacesHighlight Match
24A60L-0001-0183#75AS
25A60L-0001-0290#LM32C
26A90L-0001-0575#A
27A90L-0001-0576
28A90L-0001-0577
29A90L-0001-0580#B
30A90L-0001-0581
31A98L-0031-0028
Sheet1
 
Upvote 0
The idea is to place the material number to be checked in column "A" and then have a macro button to run the check.
The code needs to search through column C,D, and E for duplicates of the following conditions to see an exact match,
to see if numbers match without Hyphens or see if number matches without spaces. Then highlight the matches.

Thank you so much!
 
Upvote 0
Hi Thanks for sharing data and description.
Can you please highlight one data for each case as an example. It will help to create macro.
cases:
1. Exact Match
2. Match without Hyphens
3. Match without space
 
Upvote 0
Hi, See attached image. I didn't find any example for case#3
 

Attachments

  • cases.JPG
    cases.JPG
    133.9 KB · Views: 37
Upvote 0
Hi Alphix,

Use below code:

VBA Code:
Sub highlightCell()
    Dim lastRow As Integer, rowno As Integer
    Dim exactSubstr As String, noHyphen As String
    
    lastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    
    With Sheets("Sheet1")
        For rowno = 3 To lastRow
            For colno = 3 To 5
                totalRows = .Cells(Rows.Count, colno).End(xlUp).Row
                For checkRow = 3 To totalRows
                    exactSubstr = .Cells(rowno, 1)
                    noHyphen = WorksheetFunction.Substitute(.Cells(rowno, 1), "-", "")
                    If InStr(1, .Cells(checkRow, colno), exactSubstr) > 0 Then
                        .Cells(checkRow, colno).Interior.Color = vbGreen
                    End If
                    If InStr(1, .Cells(checkRow, colno), noHyphen) > 0 Then
                        .Cells(checkRow, colno).Interior.Color = vbBlue
                    End If
                Next
            Next
        Next
    End With
End Sub
 
Upvote 0
Solution
Thank you Saurabh, this works fine. Perfect solution.
I appreciate you all in the community.
 
Upvote 0
My Pleasure and thanks a lot for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

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