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

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
168
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:

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,109,424
Messages
5,528,685
Members
409,830
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top