VBA For Each Match, copy cell value to another worksheet.

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
195
Hi

Here's what I'm struggling to do;

I have a list in sheet 2, between A2:A20. And another list in sheet 1, A6:A500.

I want to go through each cell in sheet 2, A2:A20 and for each / every match in sheet 1, A6:A500 to then copy the cell value in column J into the next blank column in sheet 2 (on the matching row).

So for example, A2 (sheet2) matches A20 (sheet 1) so will then copy/paste J20 into B2 (sheet2). The next match would then paste the value of column J (sheet1) into C2 (sheet 2) and so on..

Hope I've explained this well and thank you in advance
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
How about
Code:
Sub BenGee()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Sheets("Sheet1").Range("A6:A500")
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Cl.Offset(, 9).Value
         Else
            .Item(Cl.Value) = .Item(Cl.Value) & "|" & Cl.Offset(, 9).Value
         End If
      Next Cl
      For Each Cl In Sheets("Sheet2").Range("A2:A20")
         If .Exists(Cl.Value) Then
            Cl.Offset(, 1).Resize(, UBound(Split(.Item(Cl.Value), "|")) + 1) = Split(.Item(Cl.Value), "|")
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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