View Full Version : Solved: Copy row of sheet2 (if data does not match sheet1).

06-12-2008, 07:02 PM
Hello friends,

The attachment here has a code that works, I need to edit the code to:
1. Go thru column A of sheet2.
2. if the data in column A of sheet2 does not exist in column A of sheet1, then copy the active row from column A to column D (of sheet2), and paste the rows on sheet3.
3. Start the pasting on cell A11 on sheet3.

The reasons why the code that I attach is not enough, is due to:
A. The code copies the matches between the two A columns (I don't the matches to be copied).
B. The code only copies the last column of the matching A data (I need the entire row).

Thanks a lot for your time & efforts,

06-12-2008, 11:35 PM
Sub DoCompare()
Dim cel As Range, tgt As Range
With Sheets("Sheet2")
For Each cel In Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
If Sheets("Sheet1").Columns(1).Find(cel) Is Nothing Then
Set tgt = Sheets("Sheet3").Cells(Rows.Count, 1).End(xlUp).Offset(1)
If tgt.Row < 11 Then Set tgt = Sheets("Sheet3").Cells(11, 1)
cel.Resize(, 4).Copy tgt
End If
End With
End Sub

06-17-2008, 03:19 AM
Thank you very much for your time and efforts!

I am wondering though, since it is copying and pasting, can it copy & paste the text with a "Proper" text format?

Thanks again

Bob Phillips
06-17-2008, 03:31 AM
No, it would have to process that after pasting.