Copy Data No Duplicates

mack22

New Member
Joined
Jun 18, 2018
Messages
7
Hi Guys
I need to update data from Workbook 1 to Workbook 2 just needing to have the new rows to come across and not duplicating

Workbook 1 looks like this
[TABLE="class: cms_table_cms_table, width: 500"]
<tbody>[TR]
[TD]stock no[/TD]
[TD]model name[/TD]
[TD]year model[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a005013[/TD]
[TD]911[/TD]
[TD]2003[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a005012[/TD]
[TD]911[/TD]
[TD]2003[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a005011[/TD]
[TD]911[/TD]
[TD]2005[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a005010[/TD]
[TD]911[/TD]
[TD]2005[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Workbook 2 looks the same but needs to have the new stock no's added to it each week, so workbook 2 would also need to have stock no a005011, a005012 and a005013 when command button clicked
[TABLE="class: cms_table_cms_table, width: 500"]
<tbody>[TR]
[TD]stock no[/TD]
[TD]model name[/TD]
[TD]year model[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a005010[/TD]
[TD]911[/TD]
[TD]2005[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a005009[/TD]
[TD]911[/TD]
[TD]2003[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Thanks :smile:
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I am not certain of the workbook names and don't know the worksheet names, so I have written this for two worksheets in the same workbook. Hopefully you can adapt but if not, post back with the above details.
Test with copies of your workbooks.
Code:
Sub Update_Table()
  Dim ws1 As Worksheet, ws2 As Worksheet
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  
  Set ws1 = Sheets("Sheet1")
  Set ws2 = Sheets("Sheet2")
  Set d = CreateObject("Scripting.Dictionary")
  With ws2
    a = .Range("A2", .Range("C" & .Rows.Count).End(xlUp)).Value
  End With
  For i = 1 To UBound(a)
    d(a(i, 1)) = 1
  Next i
  With ws1
    a = .Range("A2", .Range("C" & .Rows.Count).End(xlUp)).Value
  End With
  For i = 1 To UBound(a)
    If Not d.exists(a(i, 1)) Then
      k = k + 1
      For j = 1 To 3
        a(k, j) = a(i, j)
      Next j
    End If
  Next i
  If k > 0 Then ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(k, 3).Value = a
End Sub
 
Upvote 0
Hi Peter
Thanks for the response.
Workbooks are called workbook 1 and workbook 2 and sheets are both sheet1 as not to complicate things.
I get an error active x can't create an object?? any thoughts?
Cheers
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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