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
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
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
 

roofover

New Member
Joined
Sep 5, 2006
Messages
48
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
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
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
 

steve1262

Board Regular
Joined
Aug 19, 2006
Messages
126

ADVERTISEMENT

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:
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
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
 

Watch MrExcel Video

Forum statistics

Threads
1,114,041
Messages
5,545,687
Members
410,698
Latest member
Wloven
Top