Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other Microsoft Excel Posts   Ask New Question  Ask New Question With Power Editor

Finding records that don't match
J D posted at Saturday, June 06, 2009 10:10 AM

I have two separate Excel worksheets containing three fields which are common (but each contains other fields).  There is no field which uniquely identifies a record in either worksheet - even the combination of those three fields wouldn't uniquely identify a specific record.  I need to match records in worksheet A to worksheet B and identify those records in A which do not have a match in B (on the three common fields).

I tried solving this with VBA and also through an SQL statement (after importing the worksheets into tables in Access).  I'm stumped on what's the best way to accomplish this.  Any help would be extrememly appreciated!

Thanks in advance!
Joe

Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0
VBA to compare sheets
Robert Pattinson provided a rated reply to J D on Saturday, June 06, 2009 4:40 PM

Hi Joe,

This code will evaluate 2 fields and find matches or fields that don't match depending on your needs.  Next, add the unmatched record to a new sheet or bold the record in code to identify records.  Download zip file containing the code at www.jettechnical.com/sampletutorials/checkrecords.zip

Function FindUnmatchedRecords()
Dim strCompare As String
Dim strCompare1 As String
    'set up the sheet you will be comparing to on the
    'first cell to be checked
    Range("A2").Select
    'get the first sheet
    Sheets("Sheet1").Select
    'alter this to the column you want to compare.
    'this assumes that row 1 will be the header
    Range("A2").Select
    'do until the field is empty
    Do Until ActiveCell.Value = ""
        strCompare = ActiveCell.Value
        Sheets("Sheet2").Select
        strCompare2 = ActiveCell.Value
        If strCompare2 <> strCompare Then
            Sheets("Sheet3").Select
            ActiveCell.Value = strCompare2
            'set up for the next record
            ActiveCell.Offset(1, 0).Select
            'go back to Sheet2
            Sheets("Sheet2").Select
        End If
        'move to the next cell
        ActiveCell.Offset(1, 0).Select
        Sheets("Sheet1").Select
        'move to the next cell
        ActiveCell.Offset(1, 0).Select
    Loop
      

End Function

To better understand how this works, open the project, open the macro (ALT + F11) , minimize the macro window so that you can see both the spreadsheet and the macro window.  Place the cursore in the function and press F8 to step through the code and what how it executes.  Then you'll be able to modify as you need.

Happy Coding!

Robert Pattinson

 

 

 

Reply    Reply Using Power Editor
Robert Pattinson is a Senior Software Engineer at JET Technical, Inc
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0