Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Finding Differences Between Lists

It is not unusual for people to keep client information in Excel worksheets. If you have a worksheet that contains the names of all your clients, and another worksheet that contains the names of your active clients, you may want to use Excel's capabilities to discover who your inactive clients are.

There are several ways you can accomplish this task. The first is through the use of VLOOKUP. This worksheet function works great, provided your lists of clients are arranged in alphabetical order. One way to use the function is to add a status column to your "all clients" worksheet. First, make sure you select your active clients and name them "Active". (How you define a name for a selected range of cells is covered in other ExcelTips.) Then, in your full list of clients, add a column (named Status) to the right of your existing data. In the cells of the Status column, use the following formula:

=IF(ISNA(VLOOKUP(A2,Active,1,FALSE)),"Inactive","Active")

This formula assumes that the client's name is in column A of the current worksheet. The result of the formula is either "Active" or "Inactive," depending on whether there is a match between the name at A2 and the names in the Active list.

Once the Status column is in place, you can use the AutoFilter capability of Excel to filter your list based on the status column. You can then easily display the inactive clients, as desired.

It should be noted that while the above example uses the VLOOKUP worksheet function, you could just as easily compose other formulas that use functions such as HLOOKUP and MATCH. Which you use depends on your personal preferences and the way in which your data is laid out.

Another solution is to use a macro to compare each name on the "all clients" list with the names on the "active clients" list. If no match is found, then the name can be safely added to the "inactive clients" list. The following macro does just that:

Sub ListInactive()
    Dim cell As Range
    Dim SearchRng As Range

    Set SearchRng = Worksheets("Sheet2").Range("A:A")
    Counter = 1 'First row on Sheet3 contains headings
    For Each cell In Worksheets("Sheet1")
      .Range("A2:A1000") _
      .SpecialCells(xlCellTypeConstants)
        ID = cell 'Client ID
        NM = cell.Offset(0, 1) 'Client name
        MatchRow = 0
        On Error Resume Next
        MatchRow = WorksheetFunction.Match(ID, _
          SearchRng, 0)
        On Error GoTo 0
        If MatchRow = 0 Then
            Counter = Counter + 1
            Worksheets("Sheet3").Cells(Counter, 1) = ID
            Worksheets("Sheet3").Cells(Counter, 2) = NM
        End If
    Next cell
End Sub

The macro makes several assumptions about the data being examined. First, it assumes that the "all clients" worksheet is the first worksheet, and that the "active clients" worksheet is the second. Also, it is assumed that the third worksheet is blank and will end up containing the list of inactive clients. Further, the assumption is that column A contains a unique client ID number and column B contains the name of the client. When the macro is finished, the third worksheet contains the client numbers and names of all the inactive clients.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2053) applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007

Related Tips:

Organize Your Data! Using the powerful sorting capabilities of Excel can help you get your data into just the order you need. Find out how you can use the full capabilities of sorting to your benefit. Check out ExcelTips: Serious Sorting today!

 

Comments for this tip:

Dave K    19 Sep 2012, 04:18
Another option is to use the COUNTIF function.

Taking Craig's example, in cell C1 enter the formula =IF(COUNTIF(range_1,B1)>0,"Active","Inactive"). Then drag the formula down to cell C10 to show the status.

Alternatively, the formula can easily be modified to leave blanks for the active clients, making the inactive ones easier to find. This works better for longer lists.
Craig    13 Sep 2012, 19:49
Another formulaic way to compare values in lists is to compare each cell in one list to the all of the cells in the other list.
For example: A1:A50 contains a list of values. Name this range (eg – range_1).
B1:B10 contains another list of values. Some values in the second list are also in the first list.

In cell C1 enter the formula =OR(EXACT(B1,range_1)) then hit Ctrl+Shift+Enter (you are using an array).
The formula will then be {OR(EXACT(B1,range_1))}. This can be copied down for all values in the second list.

Where the value in the second list is also in the first list, the corresponding cell in column C will show TRUE. Where it is not, the value will be FALSE.

Note – this is best used for data sets that are not too large & possibly done on a separate sheet as other cell changes (or F9) will recalculate the whole list of cells again (C1:C10 in this example).
PhilP    13 Sep 2012, 13:36
Hi parsnip

If you mean will the lookup formula work this way then the best solution is to run the formula in BOTH lists

BTW - a list doesn't need to be alphabetical to work

Request my email for more asstance
parsnip    13 Sep 2012, 11:57
Will this work if each list contains entries that the other list omits?
If not, how can that be done?

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 2+3? (To prevent automated submissions and spam.)
 
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Family

Gardening

Health

Home Improvement

Legal Help

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

School and Schooling

Weddings

WindowsTips

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2013 Sharon Parq Associates, Inc.