Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How can I identify which values are not in A that are in B?

Attached is a spreadsheet. I need to know what values are in B that are not in A.

Make sense?

Column A represents the files that are in a particular directory with several that were deleted. Column B represents all of the files that SHOULD be in that directory. How can I compare the columns and get a column that represents what's missing in column A?

Thanks!
mp3s.xlsx
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Here's a macro you can use. It turns the cells in column B yellow if they aren't in column A.
Sub FindMissing()
Dim lngLastRow As Long
Dim lngRow As Long
Dim rngFound As Range

lngLastRow = Range("B1048576").End(xlUp).Row

Application.ScreenUpdating = False
Columns("A:A").Select
For lngRow = 2 To lngLastRow
    Set rngFound = Selection.Find(What:=Cells(lngRow, "B"), After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
    If rngFound Is Nothing Then
        Cells(lngRow, "B").Interior.Color = vbYellow
    End If
Next
Application.ScreenUpdating = True
End Sub

Open in new window

Just reread your question and this puts the missing values in column C.
Sub FindMissing()
Dim lngLastRow As Long
Dim lngRow As Long
Dim rngFound As Range
Dim lngNR As Long

lngNR = 2
lngLastRow = Range("B1048576").End(xlUp).Row

Application.ScreenUpdating = False
Columns("A:A").Select
For lngRow = 2 To lngLastRow
    Set rngFound = Selection.Find(What:=Cells(lngRow, "B"), After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
    If rngFound Is Nothing Then
        Cells(lngNR, "C") = Cells(lngRow, "B")
        lngNR = lngNR + 1
    End If
Next
Application.ScreenUpdating = True
End Sub

Open in new window

Avatar of Bruce Gust

ASKER

Martin, no doubt this is an elegant piece of syntax, but I'm a pig on roller skates with this kind of stuff.

I've been google-ing to try and figure out how to install your macro and run it, but I'm not finding anything that resonates with what I can understand.

I've got my macro tab. I've found that. How do I take what you did, put it in place and run it?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome! Thank you!
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015