Macro to LookUp Data and Copy/Insert only Non-Duplicated Rows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This may be an easy one for a VBA guru.

I have to update a production schedule daily by sales order number. I need
to copy and insert non-duplicated rows from Worksheet 2 into Worksheet 1
according to a specific column. For example,

Worksheet 1
Col.A Sales # Col.B Description
1 Description #1
2 Description #2
3 Description #3

Worksheet 2
Col.A Sales # Col.B Description
1 Description #1
4 Description #4
5 Description #5


The macro should only insert the rows with sales # 4 & #5 from Wk Sht. 2 to
Wk Sht 1. Addtionally, the rows should be inserted below the last row with
text in it.

Any help on this would be greatly appreciated! Thank you so much in advance!!
 
try this code

Sub test()

With Sheets("Sheet1")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh1Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

With Sheets("Sheet2")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh2Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

NewRow = LastRow + 1
For Each cell In Sh1Range
Set c = Sh2Range.Find(what:=cell.Value, LookIn:=xlValues)
If c Is Nothing Then

cell.EntireRow.Copy Destination:=Rows(NewRow)
NewRow = NewRow + 1
End If

Next cell

End Sub
 
I think this works! I will double check it manually on our print out of the
schedule. Thank You So Much for such a quick response!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top