• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 42
  • Last Modified:

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
Book1.xlsm
0
Avinash Singh
Asked:
Avinash Singh
  • 2
1 Solution
 
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

Sheets("Sheet9").Range("B2").CurrentRegion.Clear
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), ",")
        Else
            str1 = x
        End If
        
        If IsArray(y) Then
            str2 = Join(Application.Index(y, 1, 0), ",")
        Else
            str2 = y
        End If
        If str1 = str2 Then
            strMatch = "True"
        Else
            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

0
 
Avinash SinghAuthor Commented:
Thnx Neeraj sir for giving ur precious time to this post
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Avinash!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now