Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2008, 08:00 PM
Authorized User
 
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default comparing rows of two workbooks

I am trying to find difference in two workbooks, is there a way of comparing two workbooks based on rows difference. I have tried rows, entire row, and few others but no success. I am trying to take an entire row of first work book and compare it with all the rows of the second work book and if there is a match found, print it in the last column of the first workbook.
The code I have so far is:
Code:
Sub CompareBooks()

     Dim iRow As Long
     Dim iCol As Long
     Dim LastRow As Long
     Dim LastCol As Long

     Dim compareOne As String
     Dim compareTwo As String
     Dim compareOneSheet As String
     Dim compareTwoSheet As String


     compareOne = "first.csv"
     compareTwo = "second.csv"
     compareOneSheet = "first"
     compareTwoSheet = "second"


     Dim first As Range
     Dim second As Range

     Dim rowCount As Long
     rowCount = 0

     For Each second In Workbooks(compareTwo).Worksheets(compareTwoSheet).rows
        rowCount = rowCount + 1

        For Each first In Workbooks(compareOne).Worksheets(compareOneSheet).rows

            If second = first Then

                Workbooks(compareOne).Worksheets(compareTwoSheet).Cells(rows, 8).Value = "match found"
                Workbooks(compareOne).Worksheets(compareTwoSheet).Cells(rows, 8).Interior.ColorIndex = 44
                Exit For
            End If
        Next
    Next

End Sub
Any help would be greatly appreciated,
Thanks.

 
Old July 9th, 2008, 12:48 PM
Authorized User
 
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default

..couldn't solve it !!!
as a final resort, downloaded "Dupli Find" software that compares two excel or text and some other format files.
I would still like to know a way of doing that though, so any help will be greatly appreciated.
Thanks

 
Old July 9th, 2008, 08:10 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Try looping through individual cells and match it. You will be checking values in a column against another.

http://vbadud.blogspot.com/2007/10/e...ll-method.html

Another option would be to treat both Excel Sheets as Database tables and try Joins

http://vbadud.blogspot.com/2008/05/u...-database.html

Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
two workbooks--matching values within kwik10z Excel VBA 0 November 29th, 2007 11:51 AM
Opening Workbooks With Macros RollingWoodFarm Excel VBA 1 February 11th, 2007 05:48 AM
comparing rows of two DataGridViews R48 C# 0 November 7th, 2006 04:03 AM
Comparing certain rows in one table MrHicks Access 2 November 8th, 2004 04:00 PM
comparing access and Oracle rows pankaj_daga Access 0 August 3rd, 2004 06:29 PM





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