This Macro compares Worksheet1 Column A and Worksheet2 Column A and highlights and duplicates.
I would like to be able to do the same thing, but with 2 different workbooks.
I need to be able to open Workbook1, use fdialog to choose Workbook2, then use this macro to compare Workbook1.Sheet1.ColumnA and Workbook2.Sheet1.ColumnA
I am fairly new to VBA and have tried to do this but haven't been able to get it working correctly. Any help with this would be greatly appreciated.
Here is the Macro that I have now:
Sub find_duplicates()
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 would like to be able to do the same thing, but with 2 different workbooks.
I need to be able to open Workbook1, use fdialog to choose Workbook2, then use this macro to compare Workbook1.Sheet1.ColumnA and Workbook2.Sheet1.ColumnA
I am fairly new to VBA and have tried to do this but haven't been able to get it working correctly. Any help with this would be greatly appreciated.
Here is the Macro that I have now:
Sub find_duplicates()
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