Compare Lists and Add Missing Items

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi,

Is there a way I can compare the items in Column B to those in Column A. Then any item in Column A that's not in Column B would be added to the next available row in Column B.

Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
Code:
Sub CompareCols()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
      Next Cl
      For Each Cl In Range("B2", Range("B" & Rows.count).End(xlUp))
         If .exists(Cl.Value) Then .Remove Cl.Value
      Next Cl
      Range("B" & Rows.count).End(xlUp).Offset(1).Resize(.count).Value = Application.Transpose(.keys)
   End With
End Sub
 
Upvote 0
It's telling me that C1 = Nothing. I'm guessing that C1 is supposed to equal the items in column A?
 
Upvote 0
In what way is it telling you that Cl =nothing?
 
Upvote 0
Where has the code got to when you get that?
 
Upvote 0
It errors on that line. I did make the one change to include the worksheet, because the lists are on different sheets.

For Each Cl In Worksheets("Sheet1").Range("A2", Range("A" & Rows.count).End(xlUp))
 
Upvote 0
In that case you need to qualify the second part of the range
Code:
For Each Cl In Worksheets("Sheet1").Range("A2", Worksheets("Sheet1").Range("A" & Rows.count).End(xlUp))
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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