Matching duplicates

Cruiser69

Board Regular
Joined
Mar 12, 2018
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hi all.
Could anyone please help matching duplicates using VBA if this is possible

We scan codes against lots we have entered in columns D & E. We then get a master sheet sent which may contain extra lots we have not scanned or we may have scanned extra lots which are not on the sheet.
In the example below you can see all match apart from lot 4 which was not scanned
1708416823613.png



I want to add a line on columns D & E and add the corresponding number in.
Lot 6 which was scanned is not on the master sheet so D & E will need deleting
1708416852033.png


This is the final outcome I require.
1708416894943.png



Thanks for looking.

Regards,

Graham
 

Attachments

  • 1708416771873.png
    1708416771873.png
    9.3 KB · Views: 1

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi,

I suggest to try this on DUMMY data, or a COPY of your workbook - as it has the power to make a real mess of your data.

First it checks to see if Scanned Lots are inside the "Master Lot" Col C. If not, it removes them.

Then it checks each Master Lot against the scan Lot, and adds rows in.

Good Luck

Rob

Excel Formula:
Sub check_Lots()

Dim vMasterLot As Variant
Dim vScannedLot As Variant

scannedlast = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row  'Col4 to find last row
masterlast = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row  'Col3 to find last row

vMasterLot = Range("c3", "c" & masterlast)

For x = scannedlast To 3 Step -1 'first check all Scanned Lots to see if they are in Master Lot List.
     sExtraLot = True
     scanpart = Range("D" & x) 'store cell data for quicker array loop speed below
    
      For arr = LBound(vMasterLot) To UBound(vMasterLot) 'check Master Lot list to see if scanned lot exists or not.
        If vMasterLot(arr, 1) = scanpart Then
            sExtraLot = False
            Exit For 'exit arr loop if Lot exists in Master list
        End If
      Next arr
       
    If sExtraLot Then Range("D" & x, "E" & x).Delete  'remove the 2 unwanted columns not appearing in Master Lot.
 Next x
  

scannedlast = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row  'Reset Scanned Last in case of removals from previous
vScannedLot = Range("D3", "D" & scannedlast)

For x = 3 To masterlast  'now check all Master Lots to see if they are in Scanned Lot List.
     sExtraLot = True
      masterpart = Range("C" & x) 'store cell data for quicker array loop speed below
     
      For arr = LBound(vScannedLot) To UBound(vScannedLot) 'check Master see if scanned lot exists or not.
        If vScannedLot(arr, 1) = masterpart Then
            sExtraLot = False
            Exit For 'exit arr loop if Lot exists in Master list
        End If
      Next arr
       
    If sExtraLot Then
        Range("D" & x, "E" & x).Insert  'insert partial row, pushing data downward
        Range("D" & x) = Range("C" & x) 'add Master Lot no. back in to Col D
    End If
 Next x
   

End Sub

Book1
ABCDEFGHIJKLM
11
2SaleIdMaster LotScanned LotCodeSaleIdMaster LotScanned LotCode
3M1234123411V1234M1234123411V1234
4M1234123422V1334M1234123422V1334
5M1234123433V2123M1234123433V2123
6M1234123444M1234123445V2322
7M1234123455V2322M1234123456V5454
8M1234123477V4323M1234123477V4323
9M1234123488V1233M1234123488V1233
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,952
Members
449,095
Latest member
nmaske

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