Compare Two columns, find unique values, and append to second column

Nadine67

Board Regular
Joined
May 27, 2015
Messages
225
Hello and thank you for any attention this post may receive.

I have two columns of data on separate ws in the same wb. I would like to compare ws2 to ws1, identify and append unique values from ws1 to ws2.

Compare ws2 colA to ws1 colM and identify unique values in ws1 colM. Then append an array containing the unique values, colM and colT to the next blank cell of ws2 colA (A,B).

This is the code I have copied from another workbook which is returning 'Error 438 Object doesn't support this property or method' for line in red text in below code.
Code:
Sub Append_Projects()
Dim fn As String, a
Dim i As Long, e, dic As Object
'    fn = Application.GetOpenFilename("ExcelWorkbook,*.xls*")
    Application.ScreenUpdating = False
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = 1
    a = Sheets("Tables").Cells(1).CurrentRegion.Value
    For i = 2 To UBound(a, 1)
        dic(a(i, 1)) = Empty
    Next
'    With Workbooks.Open(fn)
    With Sheets("Data")
        .Unprotect Password:="BEx101"
        .Cells(1).CurrentRegion
        [COLOR=#FF0000]a = Application.Index(.Value, Evaluate("row(1:" & _
        .Rows.Count & ")"), Array(13, 20))[/COLOR]
        Sheets("Data").Protect Password:="BEx101"
'        .Close False
    End With
    
    For i = 2 To UBound(a, 1)
        If (a(i, 1) <> "") * (Not dic.exists(a(i, 1))) Then
            dic(a(i, 1)) = Array(a(i, 1), a(i, 2))
        End If
    Next
    
    For Each e In dic
        If IsEmpty(dic(e)) Then dic.Remove e
    Next
         MsgBox "All new projects have been appended."
         
    If dic.Count Then
        Sheets("Tables").Range("a" & Rows.Count).End(xlUp)(2) _
        .Resize(dic.Count, 2).Value = Application.Index(dic.items, 0, 0)
    Else
        MsgBox "No new projects to append"
    End If
    
    Application.ScreenUpdating = True
    
End Sub

Thank you again!
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,925
Members
414,416
Latest member
Nobu

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
Top