Solved

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

Posted on 2016-07-15
6
43 Views
Last Modified: 2016-07-15
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
0
Comment
Question by:brucegust
  • 4
  • 2
6 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41713687
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

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41713688
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

0
 

Author Comment

by:brucegust
ID: 41713713
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?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41713734
In Excel, Press Alt+F11 to open the Visual Basic Editor (VBE)

Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window). If you don’t see an existing module then select Insert -> Module from the context menu. Otherwise just select the module.

Copy the macro (you can use the ‘Select All’ button if you like) and paste it into the right-hand pane of the VBA editor ("Module1" window)

Press Alt+F11 again to go back to Excel

Optionally, press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’,  hold down the Shift key and type the letter A (or any other letter) and click ‘OK’. Then anytime you want to run the macro press Ctrl+Shift+A.

When you close the workbook you will need to save it as an xlsm or xls file if it’s not already one of those.
0
 

Author Closing Comment

by:brucegust
ID: 41713739
Awesome! Thank you!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41713743
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question