Hi all,
I've done some searching and found a code that works reasonable well for what I need, but I do need a little help to edit it. The below code looks in two different tabs within the same spreadsheet and finds and discrepancies, then copies the rows over to a 3rd tab, pasting them 1 under the other. What I would like it to do is, have them side by side, and also highlight the cells in the first two tabs.
This is the code.
Any help will be greatly appreciated.
I've done some searching and found a code that works reasonable well for what I need, but I do need a little help to edit it. The below code looks in two different tabs within the same spreadsheet and finds and discrepancies, then copies the rows over to a 3rd tab, pasting them 1 under the other. What I would like it to do is, have them side by side, and also highlight the cells in the first two tabs.
This is the code.
Code:
Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet, sh4 As Worksheet
Dim lr1 As Long, lr2 As Long, rng1 As Range, rng2 As Range, c As Range
Set sh1 = Worksheets("Tab1")
Set sh2 = Worksheets("Tab2")
Set sh3 = Worksheets("Tab3")
lr1 = sh1.Cells(Rows.Count, 1).End(xlUp).Row 'Get the last row with data for both list sheets
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'Establish the ranges on both sheets
Set rng1 = sh1.Range("B2:C" & lr1)
Set rng2 = sh2.Range("B2:C" & lr2)
With sh3 'If header not there, put them in
If .Range("A1") = "" Then
.Range("A1") = "Header"
.Range("B1") = "Header"
.Range("C1") = "Header"
.Range("D1") = "Header"
.Range("E1") = "Header"
End If
End With
For Each c In rng1 'Run a loop for each list ID mismatches and paste to sheet 3.
If WorksheetFunction.CountIf(rng2, c.Value) = 0 Then
'sh3.Cells(Rows.Count, 1).End(xlUp)(2) = c.Value
sh1.Rows(c.Row).Copy sh3.Cells(sh3.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
sh2.Rows(c.Row).Copy sh3.Cells(sh3.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End Sub
Any help will be greatly appreciated.