Matching data from two colums on separate sheets, and copying rows of matches to sheet 3

jukurit

New Member
Joined
May 31, 2011
Messages
13
I have information on two sheets. Sheets 1 and 2. I need to mach the data in sheet 1 column C with data in sheet 2 column P. If the numbers match i need the row in sheet 2 that has the matching number to be copied into sheet 3. (there are multiple numbers that match in sheet 2 and i set by sheet 1)
Suggestions please?
 
What data and where must be searched?
1. Data of "Yritys" sheet in "Yhteyshenkilo" sheet.
1. Data of "Yhteyshenkilo" sheet in "Yritys" sheet.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
they are numbers.
the numbers in yritys column C that match with numbers in yhteyshenkilo column P.
If the number is found in yhteyshenkilo column P i need that rown with the number and the rest of the information to be copied into Valmis.

There are 13000 thousand contacts so i really dont want to go through them manually.
 
Upvote 0
Code:
Sub Collect()

    Dim sh As Worksheet
    Dim rng1 As Range, rng2 As Range, cell As Range
    
    Set sh = Sheets("Valmis")
    
    With Sheets("Yritys")
        Set rng1 = .Range("C1", .Range("C1").End(xlDown))
    End With
    With Sheets("Yhteyshenkilo")
        Set rng2 = .Range("P1", .Range("P1").End(xlDown))
    End With
    
    For Each cell In rng1
        If WorksheetFunction.CountIf(rng2, cell.Value) Then
            sh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = cell.Value
        End If
    Next

End Sub

JackDanIce, what's the point of copying and pasting?
 
Upvote 0
Code:
Sub Collect()

    Dim sh As Worksheet
    Dim rng1 As Range, rng2 As Range, cell As Range
    
    Set sh = Sheets("Valmis")
    
    With Sheets("Yritys")
        Set rng1 = .Range("C1", .Range("C1").End(xlDown))
    End With
    With Sheets("Yhteyshenkilo")
        Set rng2 = .Range("P1", .Range("P1").End(xlDown))
    End With
    
    For Each cell In rng1
        If WorksheetFunction.CountIf(rng2, cell.Value) Then
            cell.EntireRow.Copy sh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
        End If
    Next

End Sub
 
Upvote 0
His original question asked for the entire row to be copied over when a match was found as does his question header indicate - assumed that's what was wanted.
 
Upvote 0
Ok.
Now it copied the rows from Yrutys (Sheet 1) instead of Yhteyshenkilo (Sheet 2)

Anyway the switch it around?

Getting close.

Thanks for all the help in advance. Really appreciate it!
 
Upvote 0
Try:
Rich (BB code):
Sub Collect()

    Dim sh As Worksheet
    Dim rng1 As Range, rng2 As Range, cell As Range
    
    Set sh = Sheets("Valmis")
    
    With Sheets("Yritys")
        Set rng1 = .Range("C1", .Range("C1").End(xlDown))
    End With
    With Sheets("Yhteyshenkilo")
        Set rng2 = .Range("P1", .Range("P1").End(xlDown))
    End With
    
    For Each cell In rng2
        If WorksheetFunction.CountIf(rng1, cell.Value) Then
            cell.EntireRow.Copy sh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
        End If
    Next

End Sub
 
Upvote 0
now it copies the right data.

however it stays on one row. so all the data goes through on the same row. any way to make it so it shifts down a row for each contact
 
Upvote 0
Does this work:
Rich (BB code):
Sub Collect()
    Dim sh As Worksheet
    Dim rng1 As Range, rng2 As Range, cell As Range
 
    Set sh = Sheets("Valmis")
 
    With Sheets("Yritys")
        Set rng1 = .Range("C1", .Range("C1").End(xlDown))
    End With
    With Sheets("Yhteyshenkilo")
        Set rng2 = .Range("P1", .Range("P1").End(xlDown))
    End With
 
    For Each cell In rng2
        If WorksheetFunction.CountIf(rng1, cell.Value) Then
            cell.EntireRow.Copy
            sh.Cells(Rows.Count, 16).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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