Match and Copy Data

roofover

New Member
Joined
Sep 5, 2006
Messages
48
Does anyone have a code for this?


Match Data in worksheet "Sheet1" (search all rows) Columns A-E . With Data in worksheet "sheet2" (search all rows) Columns A-E if Match is exact cut and paste entire row to "Sheet3", loop until no match is found.

Thank you for any help !!

SA
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
try;
Code:
Sub test()
Dim i As Long
Application.CutCopyMode = False
For i = 1 To Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row
    With Sheets("Sheet2").Columns("a")
    Set c = .Find(Cells(i, "a").Value, , , xlWhole)
    If Not c Is Nothing Then
    If c.Offset(, 1) = Cells(i, "b") _
    And c.Offset(, 2) = Cells(i, "c") _
    And c.Offset(, 3) = Cells(i, "d") _
    And c.Offset(, 4) = Cells(i, "e") Then
      Sheets("Sheet1").Cells(i, "a").EntireRow.Copy Sheets("Sheet3").Range("a" & Rows.Count).End(xlUp).Offset(1)
    End If
    End If
    End With
Next
Application.CutCopyMode = True
End Sub
 
Upvote 0
Match Cut and Paste to another sheet

This is almost what I am looking for but I am not sure if I explained it correctly.

Match Data in worksheet "Sheet1" (search all rows) Columns A-E . With Data in worksheet "sheet2" (search all rows) Columns A-E if Match is exact cut and paste entire row to "Sheet3", loop until no match is found.

Match data as described above but, if a match is found cut the row (remove the data) from "sheet2" only and paste it to the next available row in "Sheet3". So on the next loop that matched data would be completly removed from "Sheet2".

I hope this explains it better. Thank you for your help !!!

SA
 
Upvote 0
try;
Code:
Sub test()
Dim i As Long
Application.CutCopyMode = False
For i = 1 To Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row
    With Sheets("Sheet2").Columns("a")
    Set c = .Find(Cells(i, "a").Value, , , xlWhole)
    If Not c Is Nothing Then
    If c.Offset(, 1) = Cells(i, "b") _
    And c.Offset(, 2) = Cells(i, "c") _
    And c.Offset(, 3) = Cells(i, "d") _
    And c.Offset(, 4) = Cells(i, "e") Then
    c.EntireRow.Cut Sheets("Sheet3").Range("a" & Rows.Count).End(xlUp).Offset(1)
    End If
    End If
    End With
Next
Application.CutCopyMode = True
End Sub
 
Upvote 0
Match 4 columns and paste row

Works great !! Thank you so much !! :) :)


Let me ask you one more thing if I may. Keep the code the same except column "e" (which is a numeric value) would only match if it is equal to or less than the value. So "Sheet2", Column "e" value would be equal to or less than "Sheet1", column "e". I tryed

Code:
And c.Offset(, 4) =< Cells(i, "e") Then

AND

Code:
And c.Offset(, 4) => Cells(i, "e") Then

but it did not work.

Thanks again for the help.

SA :LOL:
 
Upvote 0
try;
Code:
Sub test()
Dim i As Long
Application.CutCopyMode = False
For i = 1 To Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row
    With Sheets("Sheet2").Columns("a")
    Set c = .Find(Cells(i, "a").Value, , , xlWhole)
    If Not c Is Nothing Then
    a = Cells(i, "e").Value
    b = c.Offset(, 4) - a
    If c.Offset(, 1) = Cells(i, "b") _
    And c.Offset(, 2) = Cells(i, "c") _
    And c.Offset(, 3) = Cells(i, "d") _
    And b < 1 Then
    c.EntireRow.Cut Sheets("Sheet3").Range("a" & Rows.Count).End(xlUp).Offset(1)
    End If
    End If
    End With
Next
Application.CutCopyMode = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,218,620
Messages
6,143,522
Members
450,492
Latest member
Rusbus1972

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