compare rows of multiple sheets

Compare sheet1 row with sheet2 row
compare sheet3 row with sheet4 row
compare sheet5 row with sheet6 row
compare sheet7 row with sheet8 row
and paste the result to sheet9
we have to compare one complete row with another sheet complete row
Avinash SinghAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
What about this?
The code will populate three columns on Sheet9
Column B --> Sheet names which are being compared.
Column C --> Row#
Column D --> Match result

That way you would know that the Row# and match result belong to which sheets.
Sub CompareRows()
Dim i As Integer, r As Long, lr As Long, lc1 As Long, lc2 As Long, j As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Dim strSh As String, strRow As String, str1 As String, str2 As String, strMatch As String
Dim x, y, Result()

Application.ScreenUpdating = False

For i = 1 To 7 Step 2
    Set ws1 = Sheets(i)
    Set ws2 = Sheets(i + 1)
    lr = ws1.Cells(Rows.Count, 1).End(xlUp).Row
    ReDim Result(1 To lr, 1 To 3)
    For r = 1 To lr
        lc1 = ws1.Cells(r, Columns.Count).End(xlToLeft).Column
        lc2 = ws2.Cells(r, Columns.Count).End(xlToLeft).Column
        x = ws1.Range("A" & r, ws1.Cells(r, lc1)).Value
        y = ws2.Range("A" & r, ws2.Cells(r, lc2)).Value
        If IsArray(x) Then
            str1 = Join(Application.Index(x, 1, 0), ",")
            str1 = x
        End If
        If IsArray(y) Then
            str2 = Join(Application.Index(y, 1, 0), ",")
            str2 = y
        End If
        If str1 = str2 Then
            strMatch = "True"
            strMatch = "False"
        End If
        Result(r, 1) = ws1.Name & " - " & ws2.Name
        Result(r, 2) = "Row" & r
        Result(r, 3) = strMatch
    Next r
    Range("B" & Rows.Count).End(3)(2).Resize(UBound(Result, 1), 3).Value = Result
Next i

Application.ScreenUpdating = True
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Avinash SinghAuthor Commented:
Thnx Neeraj sir for giving ur precious time to this post
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Avinash!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.