AllExperts > Experts 
Search      

Excel

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Excel Answers
Question Library

Ask a question about Excel
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Stuart Resnick
Expertise
I can answer any question relating to MS Excel formulas, or to programming with vba (Visual Basic for Applications) in the Excel environment

Experience
As a consultant, I've designed Excel tools since the 90s, working for the Federal Reserve Bank, AT&T, and (currently) Gap Inc.

 
   

You are here:  Experts > Computing/Technology > Business Software > Excel > Cross checking two lists

Topic: Excel



Expert: Stuart Resnick
Date: 7/18/2008
Subject: Cross checking two lists

Question
I would like a macro to do the following please:

For every customer in column A on a list of customers on sheet 1 check the customer name against a customer list in column A on sheet 2
If not found in column A on sheet 2, add customer name to the bottom of the list on sheet 2
Continue until the end of the list on sheet 1

Thank you


Answer
Example: the lists on Sheet1 and Sheet2 both begin in cell A1. Any value in the Sheet1 list that's not on the Sheet2 list gets added to bottom of Sheet2 list:

Sub copyFromColA()
   Dim copyFrom As Range, copyTo As Range
   Set copyFrom = Sheets("sheet1").Range("a1")
   Set copyTo = Sheets("sheet2").Range("a1")
   Do Until copyTo = ""
       Set copyTo = copyTo.Offset(1)
   Loop
   Do Until copyFrom = ""
       If IsError(Application.Match(copyFrom, copyTo.EntireColumn, 0)) Then
           copyTo = copyFrom
           Set copyTo = copyTo.Offset(1)
       End If
       Set copyFrom = copyFrom.Offset(1)
   Loop
End Sub

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.