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!
 
Spoke a little too soon. It errors out if the lists are identical. Is there a line I can add that says this is OK? NEVERMIND, looks like it was user error. sorry, and thanks again!
 
Last edited:
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Just change the last line to
Code:
      [COLOR=#ff0000]If .count > 0 Then [/COLOR]Range("B" & Rows.count).End(xlUp).Offset(1).Resize(.count).Value = Application.Transpose(.keys)
 
Upvote 0
If I wanted to use this on multiple lists, would i need to change CreateObject("scripting.dictionary")? I changed C1, but I'm still getting the same list.
 
Upvote 0
What do you mean by "multiple lists"?
 
Upvote 0
THANKS for all your help! I figure it out, i forgot to change one of the other variables. I'm actually comparing multiple sets of list, 2 at a time.

What if i wanted to compare A to B and if A was on B then delete it from A? would I make this change, plus flip the code so B comes first?
If Not .exists(C2.Value) Then .Delete C2.Value, Nothing
 
Upvote 0
Do you mean you want to delete the cell from the sheet?
 
Upvote 0
Try
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, Cl
      Next Cl
      For Each Cl In Range("B2", Range("B" & Rows.count).End(xlUp))
         If .Exists(Cl.Value) Then
            .Item(Cl.Value).Delete xlShiftUp
            .Remove Cl.Value
         End If
      Next Cl
      If .count > 0 Then Range("B" & Rows.count).End(xlUp).Offset(1).Resize(.count).Value = Application.Transpose(.keys)
   End With
End Sub
 
Upvote 0
This brings everything over like the first code. For this one i just want to say if the item in column A is also in coulmn B, then just delete it from column A.
 
Upvote 0
In that case simply delete this line
Code:
If .count > 0 Then Range("B" & Rows.count).End(xlUp).Offset(1).Resize(.count).Value = Application.Transpose(.keys)
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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