Copy data from one sheet to another sheet ignoring the duplicate at destination sheet

thespardian

Board Regular
Joined
Aug 31, 2012
Messages
119
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi there!
On Sheet6 (D Data), The range K3:K50 have an array formula for the extraction of unique Centre list. And I want to copy the only cells that contain text. (range K3:K9 in the given example)......... And
1.png



paste it at the end of column B on Sheet 7 (Compile D) by ignoring the names already available in the existing list at destination sheet (i.e Sheet 7 (Compile D))


2.png


I mean, duplicate names are not required and the order of list should not be disturbed on Sheet7(Compile D).
Any help on the matter would be highly appreciated. TIA

3.png
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this
VBA Code:
Sub CompileD()

Dim nRow As Long
Dim key As Variant
Dim cell As Range, rngUnique As Range
Dim rngComp As Range, rngFound As Range
Dim wsData As Worksheet, wsComp As Worksheet
Dim DictData As Object

Set DictData = CreateObject("Scripting.Dictionary")
Set wsData = ActiveWorkbook.Sheets("D Data")
Set wsComp = ActiveWorkbook.Sheets("Compiled D")
Set rngUnique = wsData.Range("K3", "K50")

Application.ScreenUpdating = False

For Each cell In rngUnique
    If Not cell = "" Then
        DictData.Add cell.Value, Nothing
    Else
        Exit For
    End If
Next

nRow = wsComp.Cells(Rows.Count, "C").End(xlUp).Row
If Not nRow = 3 Then
    Set rngComp = wsComp.Range("C3", "C" & nRow)
End If

For Each key In DictData.keys
    Set rngFound = rngComp.Find(What:=key, LookAt:=xlWhole)
    If rngFound Is Nothing Then
        nRow = nRow + 1
        wsComp.Range("C" & nRow) = key
    End If
Next
Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Try this
VBA Code:
Sub CompileD()

Dim nRow As Long
Dim key As Variant
Dim cell As Range, rngUnique As Range
Dim rngComp As Range, rngFound As Range
Dim wsData As Worksheet, wsComp As Worksheet
Dim DictData As Object

Set DictData = CreateObject("Scripting.Dictionary")
Set wsData = ActiveWorkbook.Sheets("D Data")
Set wsComp = ActiveWorkbook.Sheets("Compiled D")
Set rngUnique = wsData.Range("K3", "K50")

Application.ScreenUpdating = False

For Each cell In rngUnique
    If Not cell = "" Then
        DictData.Add cell.Value, Nothing
    Else
        Exit For
    End If
Next

nRow = wsComp.Cells(Rows.Count, "B").End(xlUp).Row
If Not nRow = 3 Then
    Set rngComp = wsComp.Range("B3", "B" & nRow)
End If

For Each key In DictData.keys
    Set rngFound = rngComp.Find(What:=key, LookAt:=xlWhole)
    If rngFound Is Nothing Then
        nRow = nRow + 1
        wsComp.Range("B" & nRow) = key
    End If
Next
Application.ScreenUpdating = True
    
End Sub
Thanks a lot for your guidance. I just changed the Column name (B instead of C) and its working very well.
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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