Range compare help needed

jerry203

New Member
Joined
Jul 4, 2022
Messages
3
Office Version
  1. 2007
Platform
  1. Windows
Hi all, I need a bit of help. I have been struggling with some code that needs to look for the contents of one range in another range in a separate workbook.
I have been looking at all kinds of sample code but I don't know the 'best practice' approach for what I need to do.

I have two workbooks, DMG and DataExtract, I need to take a range from the sheet "Group" in DMG and search a range in sheet "Data" from DataExtract for any matches. When a match is found I'd like it to copy the row and paste it in the blank sheet "Output" also under the DataExtract workbook. It then needs to carry on looking for matches as "Data" may contain more than one of each value in "Group".

I'm not sure the dictionary object is ideal but it is the rabbit hole I'm stuck in, any help will be greatly appreciated
Regards
Jerry


VBA Code:
''Dim Cl As Range

''   Dim Dic As Object
''   Dim NumberRows As Long
''   Dim wbSource As Workbook, wbTarget As Workbook
''   Dim SrcSht As Worksheet, TgtSht As Worksheet
 
''   Application.ScreenUpdating = False
''   Application.Calculation = xlCalculationManual

''   Set Dic = CreateObject("scripting.dictionary")
''   Set wbSource = Workbooks("DMG.xlsm")
''   Set wbTarget = Workbooks("DataExtract.xlsm")
''   Set SrcSht = wbSource.Sheets("Group")
''   Set TgtSht = wbTarget.Sheets("Data")
''   Set Output = wbTarget.Sheets("Output")
  
''   NumberRows = TgtSht.Cells(Rows.Count, 6).End(xlUp).Row ' last row in column F

''   For Each Cl In TgtSht.Range("F2:F" & NumberRows)
''      Dic(Cl.Value) = Empty
''   Next Cl
''   For Each Cl In SrcSht.Range("B2", SrcSht.Range("B" & Rows.Count).End(xlUp))
''      If Dic.Exists(Cl.Value) Then
''         Output.Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Cl.Value
''      End If
''   Next Cl
''   Application.ScreenUpdating = True
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
@jerry203
Welcome to MrExcel.
1. Could you post some sample data from both sheets? also the result as expected?
2. Data in Sheets("Group") col B, are there any duplicate?
 
Upvote 0
@jerry203
Welcome to MrExcel.
1. Could you post some sample data from both sheets? also the result as expected?
2. Data in Sheets("Group") col B, are there any duplicate?
Thank you.
The data in Sheets("Group") col B is userid's so examples would be smithc, turnerd2, harrisj, jonesp1 etc
There won't be any duplicates in Sheets("Group")
I can't post much sample data from Sheets("Data") as I have to de-identify it but here is a small bit
ex.jpg
 
Upvote 0
Would I be better to not use the dictionary object and just have some kind of if/else loop?
 
Upvote 0
I think dictionary object is a good idea.
But I don't quite understand what you're trying to do. Can you explain in more detail?
I need to take a range from the sheet "Group" in DMG and search a range in sheet "Data" from DataExtract for any matches.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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