Find duplicate column values across multiple workbooks, and get data row and set row data to new sheet

itomedina25

New Member
Joined
Mar 19, 2024
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
Hi,
I have multiple excel workbooks with data on 5 columns (A to E). The first column is the ID column. The other 4 columns are the data for that ID. Am only focus on columns A and B. Columns A and B are to be check for duplicates, specifically column B on every workbook. All workbooks are hold in the same folder. If B has data for that ID(column A) and is not equal to B in all other workbooks, then grab that row data and export to active workbook sheet1. Else if data are equal on column B export to sheet2 on active workbook. Finally, row 1, 2, and 3 are headers, those rows have to be ignored on the search.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
what part of the code are you having difficulty with?
If you're not proficient at coding, have you tried recording your actions and going over the code.
I suggest checking out how to loop through all workbooks in a folder.
 
Upvote 0
The code is copying every row from each workbook inside a file. I need to compare values on column B Cells with each other workbook and copy the duplicates on sheet 2 and the non duplicates for that column on sheet 3.
here is the code:
Sub tOriginal()

Dim fName As String
Dim fPath As String
Dim wb As Workbook
Dim sh As Worksheet
Dim i As Long
Dim selCell As Range
Dim dataRng As Range


Set sh = ActiveSheet

fPath = ThisWorkbook.Path & "\"
fName = Dir(fPath & "*.xlsx*")
Do
If fName <> ThisWorkbook.Name Then

Set wb = Workbooks.Open(fPath & fName)

If sh.Range("B3") = "" Then
wb.Sheets(1).Range("A3", Sheets(1).Cells(3, Columns.Count).End(xlToLeft)).Copy sh.Range("B3")
sh.Range("A2") = "Source"
End If

wb.Sheets(1).UsedRange.Offset(4).Copy sh.Cells(Rows.Count, 2).End(xlUp)(2)

With sh
.Range(.Cells(Rows.Count, 1).End(xlUp)(2), .Cells(Rows.Count, 2).End(xlUp).Offset(, -1)) = fName
End With

wb.Close

End If

Set wb = Nothing

fName = Dir

Loop Until fName = ""

For i = sh.UsedRange.Rows.Count To 2 Step -1
If Application.CountIf(sh.Range("B:B"), sh.Cells(i, 2).Value) = 1 Then Rows(i).Delete
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,957
Messages
6,175,622
Members
452,661
Latest member
Nonhle

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