Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 12th, 2007, 02:41 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default code to check values in two columns??

Here is my problem:

I want to check each cell in column A with every cell in column B and want to copy the cell to another text file if any cell value in column A does NOT exist in column B and vice versa. That might be a very simple code but since I know writing codes as much as writing in French :) this will take my days to figure it out alone.

I will appreciate any tips.

Thanks in advance.

Reply With Quote
  #2 (permalink)  
Old December 12th, 2007, 07:55 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To be more specific assume that my first column A includes:

William
Joe
Tom
John
Bill

and column B includes:

Bill
William
Amy
John
Tom
Henry


I want the code to find me Joe and copy&paste it somewhere (preferably in a text file or in another sheet lets say to A1 in sheet 2) and next find Amy (and then Henry) and copy paste in another sheet (to lets say A1 and A2 in sheet 3) or in a text file.

Joe must be found because it is in column A but not in column B.
Amy&Henry must be found because they are in column B but not in column A.

Can anyone help me on this ?

Reply With Quote
  #3 (permalink)  
Old December 13th, 2007, 07:39 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: , , Finland.
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
This should do the trick


Sub FindNames()
Dim Range1(), Range2()
Dim bFound As Boolean
Dim RowNo As Integer


Range1 = Range("A1:" & Range("A1").End(xlDown).Address)
Range2 = Range("B1:" & Range("B1").End(xlDown).Address)

For i = 1 To UBound(Range1)
    bFound = False
    For j = 1 To UBound(Range2)
        If Range1(i, 1) = Range2(j, 1) Then
            bFound = True
            Exit For
        End If
    Next
    If bFound = False Then
        RowNo = RowNo + 1
        Sheets(2).Cells(RowNo, 1) = Range1(i, 1)
    End If
Next
RowNo = 0
For i = 1 To UBound(Range2)
    bFound = False
    For j = 1 To UBound(Range1)
        If Range1(j, 1) = Range2(i, 1) Then
            bFound = True
            Exit For
        End If
    Next
    If bFound = False Then
        RowNo = RowNo + 1
        Sheets(3).Cells(RowNo, 1) = Range2(i, 1)
    End If
Next

End Sub

-vemaju
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy columns based on cell values EricB123 Excel VBA 0 December 18th, 2007 12:51 AM
getting values from template columns itemtemplate Laxmikant_it ASP.NET 1.0 and 1.1 Professional 4 February 6th, 2007 04:19 PM
Check values Dj Kat MySQL 2 March 23rd, 2006 04:10 AM
Displaying values in multiple columns in Combo abhijeet BOOK: Professional C#, 2nd and 3rd Editions 1 June 15th, 2005 07:01 AM
how can i check for duplicate values before saving noor ASP.NET 1.0 and 1.1 Basics 3 June 10th, 2005 09:28 AM



All times are GMT -4. The time now is 07:04 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.