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
stock nomodel nameyear model
a0050139112003
a0050129112003
a0050119112005
a0050109112005

<tbody>
</tbody>


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
stock nomodel nameyear model
a0050109112005
a0050099112003

<tbody>
</tbody>

Thanks :)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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,215,650
Messages
6,126,016
Members
449,280
Latest member
Miahr

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