The following macro compares Column A in Sheet1 and Column A in Sheet2. If the values match, it highlights the cell red.
I need help modifying the code so that this compares Workbook1 and Workbook2 instead of Sheet1 and Sheet2.
I currently have to copy and paste from 1 workbook to the other to run this macro, I would like to compare 2 different workbooks instead.
Macro finds duplicates in ColumnA of Sheet1 & Sheet2
Need macro to compare duplicates of Workbook1 & Workbook2
Any help with this would be greatly appreciated
Sub find_duplicates()
'LR1 should be Workbook1, Sheet1, Column A
'LR2 should be Workbook2, Sheet1, Column A
LR1 = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row 'last row in old
LR2 = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row 'last row in new
For i = 2 To LR1 'loop thru all the cells in Col A of old
For j = 2 To LR2 'loop thru all the cells in Col A of new
'if the cells match then color them red
If Sheets("Sheet1").Cells(i, "A") = Sheets("Sheet2").Cells(j, "A") Then
Sheets("Sheet1").Cells(i, "A").Interior.Color = RGB(255, 0, 0) 'Red
Sheets("Sheet2").Cells(j, "A").Interior.Color = RGB(255, 0, 0) 'Red
End If
Next j
Next i
End Sub
I need help modifying the code so that this compares Workbook1 and Workbook2 instead of Sheet1 and Sheet2.
I currently have to copy and paste from 1 workbook to the other to run this macro, I would like to compare 2 different workbooks instead.
Macro finds duplicates in ColumnA of Sheet1 & Sheet2
Need macro to compare duplicates of Workbook1 & Workbook2
Any help with this would be greatly appreciated
Sub find_duplicates()
'LR1 should be Workbook1, Sheet1, Column A
'LR2 should be Workbook2, Sheet1, Column A
LR1 = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row 'last row in old
LR2 = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row 'last row in new
For i = 2 To LR1 'loop thru all the cells in Col A of old
For j = 2 To LR2 'loop thru all the cells in Col A of new
'if the cells match then color them red
If Sheets("Sheet1").Cells(i, "A") = Sheets("Sheet2").Cells(j, "A") Then
Sheets("Sheet1").Cells(i, "A").Interior.Color = RGB(255, 0, 0) 'Red
Sheets("Sheet2").Cells(j, "A").Interior.Color = RGB(255, 0, 0) 'Red
End If
Next j
Next i
End Sub